htaccess的规则转发/登录/和/登录到同一页? [英] htaccess rule to forward /login/ and /login to same page?
问题描述
我在目前的.htaccess文件以下规则来重定向 /视频/登录/
要求 /videos/login.php
I have the following rule in my current .htaccess file to redirect /videos/login/
requests to /videos/login.php
RewriteRule login/ /videos/login.php
这工作正常,如果我使用访问登陆页面 http://mysite.com/videos/login/
但是当我试图访问使用相同的页面 http://mysite.com/videos/login
(没有结束斜线),那么它给了我404找不到网页的错误。
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.
请告诉我这将是.htaccess文件的正确的规则,以便为 http://mysite.com/videos/login/
或<$ C任何要求$ C> http://mysite.com/videos/login 将指向同一个/videos/login.php页。
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.
感谢
推荐答案
只要最后的斜线可选的:
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]
这篇关于htaccess的规则转发/登录/和/登录到同一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!