开发者

.htaccess 301 redirect problem

开发者 https://www.devze.com 2023-03-07 08:21 出处:网络
i try to redirect url开发者_如何学Go\'s like: example.com/video/1640/video-name to example.com/video/1640/video-name/

i try to redirect url开发者_如何学Go's like:

example.com/video/1640/video-name

to

example.com/video/1640/video-name/

i've tried with:

RewriteRule ^video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
RewriteRule ^video/([^/]*)/([^/]*)$ /video/([^/]*)/([^/]*)/ [R=301,L]

but it is not working

my currently htaccess file has only the first line:

RewriteRule ^video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]

and videos only loads at

example.com/video/1640/video-name/

url type

i want to redirect the non-backslash url type

example.com/video/1640/video-name

to the correct one (the one with the backslash)

How can i do this?


Your second rule should be RewriteRule ^video/([^/]*)/([^/]*)$ /video/$1/$2/ [R=301,L]

Or you could forgo the redirect totally, and just say RewriteRule ^video/([^/]*)/([^/]*)/?$ video.php?id=$1&title=$2 [L] which will allow both to view your video.


Update FallingBullets is right (see the comments on this answer), his answer better suites the OP's problem, so please ignore this answer (I am leaving it for reference, though).


Maybe you simply have to prefix your pattern with a /?? E. g.

RewriteRule ^/?video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
RewriteRule ^/?video/([^/]*)/([^/]*)$ /video/([^/]*)/([^/]*)/ [R=301,L]
#            ^ these ones

instead of

RewriteRule ^video/([^/]*)/([^/]*)/$ video.php?id=$1&title=$2 [L]
RewriteRule ^video/([^/]*)/([^/]*)$ /video/([^/]*)/([^/]*)/ [R=301,L]

since you are anchoring the pattern at the beginning of the path (using ^).

0

精彩评论

暂无评论...
验证码 换一张
取 消