Question

I'm rewriting a query to a SEO friendly URL..
Basically, I'm rewriting
http://example.com/forums/category?v=Name
to
http://example.com/forums/category/Name

My problem is that the $_GET['v'] is returning Name.php instead of Name.. Here is my .htaccess:

<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 

ErrorDocument 400 /404.htm
ErrorDocument 401 /404.htm
ErrorDocument 403 /404.htm
ErrorDocument 404 /404.htm
ErrorDocument 500 /404.htm

RewriteEngine on 
RewriteRule ^(.*)/$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ $1.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /forums/view\.php\?v=([^&]+)&a=(.+)\ HTTP
RewriteRule ^ /forums/view/%1/%2 [R=301,L]
RewriteRule ^forums/view/([^/]+)/([^/]+)/?$ /forums/view.php?v=$1&a=$2 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /forums/category\.php\?v=([^&]+)\ HTTP
RewriteRule ^ /forums/category/%1 [R=301,L]
RewriteRule ^forums/category/([^/]+)/?$ /forums/category.php?v=$1 [L]
Was it helpful?

Solution

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ $1.php [L]

these 2 strings mean that if your file is absent (and http://example.com/forums/category/Name is obviously absent) you transform it to http://example.com/forums/category/Name.php and the rules proceed further - so you have Name.php as a parameter in your category.php instead of Name

To solve your problem just move these 2 strings below other rules.

OTHER TIPS

The following rule matches before the rule that writes that part to the query string.

#First matched rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(([^/]+/)*[^.]+)$ $1.php [L]

#Before this rule
RewriteRule ^forums/category/([^/]+)/?$ /forums/category.php?v=$1 [L]

It seems that the rule that is matched first is meant to be 'if-all-other-cases-fail-do-this', so you should move that rule to the bottom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top