views:

284

answers:

4

I have the following rule in my current .htaccess file to redirect /videos/login/ requests to /videos/login.php

RewriteRule login/ /videos/login.php

This works fine if I am access login page using http://mysite.com/videos/login/ but when I am trying to access the same page using http://mysite.com/videos/login (without ending slash) then it gives me "404 page not found" error.

Please tell me what will be the correct rule of .htaccess file so that any request for http://mysite.com/videos/login/ or http://mysite.com/videos/login will point to the same /videos/login.php page.

Thanks

+4  A: 

Just make the trailing slash optional:

RewriteRule ^videos/login/?$ /videos/login.php

But you should better use just one variant (with or without trailing slash) and redirect one to the other:

# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ /$0/ [L,R=301]

# remove trailing slash
RewriteRule (.*)/$ /$1 [L,R=301]
Gumbo
@Gumbo your Rule is working fine, its opening the same page with and without slash, but I want when any one will access the /videos/login then he will be redirected to /videos/login/ is it possible using htaccess.
Prashant
I just mentioned both options. If you want the trailing slash, just use the former.
Gumbo
But #add trailing slash will add slashes to all my URLs, which I don't want, there are some selected URLs for which I want this facility
Prashant
A trailing slash will be added to every URL path that cannot be mapped to an existing file (`RewriteCond %{REQUEST_FILENAME} !-f`). But if you don’t want that, list those URL paths you want it for with a `RewriteCond %{REQUEST_URI} ^/(videos/login|foo/bar|baz/quux|…)$` instead.
Gumbo
A: 

Using mod_rewrite

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/videos/login/?$
RewriteRule (.*) /videos/login.php [L,R=301]
DavidWinterbottom
A: 
redirect 301 /videos/login/index.html http://yoursite.com/videos/login.php

The server will change the address http://mysite.com/videos/login/ and http://mysite.com/videos/login both to http://mysite.com/videos/login/index.html, based on the configuration but this is default. Before it encounters a 404 this address is redirected to the new one. At least this works at my site.

Had to use pre because the site let's me post only one hyperlink :/

Ruud v A
+1  A: 

This work fine for me:

Rewriterule ^login(/|)$ /videos/login.php

Naikon