0

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]
2
  • $_GET['v'] in which file? Commented Jan 2, 2014 at 13:06
  • http://example.com/forums/category/Computing returns Computing.php Commented Jan 2, 2014 at 13:09

2 Answers 2

1
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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.