m3tsys
m3tsys

Reputation: 3969

.htaccess 301 redirect problem

i try to redirect url'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?

Upvotes: 0

Views: 208

Answers (2)

Axel Knauf
Axel Knauf

Reputation: 1683

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 ^).

Upvotes: 0

fbstj
fbstj

Reputation: 1714

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.

Upvotes: 2

Related Questions