Mona Abdelmajeed
Mona Abdelmajeed

Reputation: 686

url rewrite : more than one rule in htaccess

please Help to solve this problem

RewriteEngine On
ErrorDocument 400 /tmp/error/404.html
ErrorDocument 401 /404.html
ErrorDocument 403 /404.html
ErrorDocument 404 /404.html
ErrorDocument 500 /404.html
RewriteBase /
DirectoryIndex index.php
RewriteRule ^([0-9a-z\-\_]+)?$ /index.php?url=$1 [L,QSA,NC]
#RewriteRule ^showthread.php?t=([0-9]+)/?$ /vb/showthread.php?t=$1 [NC]

all rules work but the comments rule i can't write it

can you help me to write this rule

I want to redirect this path /showthread.php?t=[0-9] to /vb/showthread.php?t=[0-9]

with out problems in seo ?

Upvotes: 1

Views: 276

Answers (2)

ziesemer
ziesemer

Reputation: 28707

RewriteCond %{QUERY_STRING} ^t=(\d+)$
RewriteRule ^showthread\.php /vb/showthread.php?t=%1 [NC]

Reference: http://wiki.apache.org/httpd/RewriteQueryString

Note, per the example shown there as well, this will only work if t is the only parameter in the query string - but it could be expanded to allow for others as well, such as:

RewriteCond %{QUERY_STRING} (?:^|&)t=(\d+)(?:&|$)
RewriteRule ^showthread\.php /vb/showthread.php?t=%1 [NC]

(I did just test this, and it seems to work without issue.)

Also, if you want this to redirect, rather than just proxying the request to the other php file, you'll want to add something like [R=301] to the end of the RewriteRule.

Upvotes: 3

tcak
tcak

Reputation: 2212

One problem I see is, you have written ^showthread.php?t=([0-9]+)/?$ as regex. In regular expression .(dot) means anything can be. Try to change commented line with that,

RewriteRule ^showthread\.php?t=([0-9]+)/?$ /vb/showthread.php?t=$1 [NC]

Another thing is,

RewriteRule ^([0-9a-z\-\_]+)?$ /index.php?url=$1 [L,QSA,NC]

This line takes all the requests directly and redirects to index.php. Because you said in regex that even it is empty, send the request to index.php again. Or maybe you have forgotten to put / (slash) before ? (question mark). Not putting that changes that regex's mean.

Upvotes: 1

Related Questions