views:

61

answers:

1

I'm trying to write a URL like below, but when I try to call the seo queryparam, it always returns index.php. Any idea why it isn't returning the correct value for 'seo'?

RewriteRule ^([^/]*)$ index.php?c=home&m=details&seo=$1 [L]

The URL it should forward from would be something like this: http://domain.com/The-Name-of-the-Product. That URL should be rewritten to http://domain.com/index.php?c=home&m=details&seo=The-Name-of-the-Product, but instead it ends up as http://domain.com/index.php?c=home&m=details&seo=index.php

+3  A: 

Various events cause a URL to go back through the rewrite process. You can use RewriteCond to prevent this:

RewriteCond $1 !^index.php$
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

From the mod_rewrite technical details:

When you manipulate a URL/filename in per-directory context mod_rewrite first rewrites the filename back to its corresponding URL (which is usually impossible, but see the RewriteBase directive below for the trick to achieve this) and then initiates a new internal sub-request with the new URL. This restarts processing of the API phases.

This catches people all the time.

outis
beat me to it, but that is it exactly! +1
jaywon
Worked perfectly! Many thanks!!!
mike
I did find one issue. My domain does not work with out entering index.php in to the URL now. http://domain.com does not work. It just takes me to a blank white page. Any ideas?
mike
Change the '*' metacharacter to a '+' so that the URL has at least one character in the path. Answer updated.
outis