htaccess的规则转发/登录/和/登录到同一页?(htaccess rule to forwar

2019-07-29 23:12发布

我在我目前的.htaccess文件以下规则来重定向/videos/login/请求/videos/login.php

RewriteRule login/ /videos/login.php

如果我用我的访问登陆页面也能正常工作http://mysite.com/videos/login/但是当我试图访问使用同一页面http://mysite.com/videos/login (没有结束斜线),那么它给了我“404页找不到”错误。

请告诉我会是怎样的.htaccess文件的正确规则,以便对任何要求http://mysite.com/videos/login/http://mysite.com/videos/login将指向相同/视频/的login.php页面。

谢谢

Answer 1:

只是使尾部斜杠可选:

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

但是你最好只使用一个变种(带或不带斜线)和重定向一个到另一个:

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

# remove trailing slash
RewriteRule (.*)/$ /$1 [L,R=301]


Answer 2:

这项工作对我罚款:

重写规则^登录(/ |)$ /videos/login.php



Answer 3:

使用mod_rewrite

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/videos/login/?$
RewriteRule (.*) /videos/login.php [L,R=301]


Answer 4:

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.

不得不因为网站让我们我只发布一个超链接使用前:/



文章来源: htaccess rule to forward /login/ and /login to same page?