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
Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite ( olle? p=1 will be rewritten as index.
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]
This work fine for me:
Rewriterule ^login(/|)$ /videos/login.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With