将旧链接重定向到新链接

时间:2018-01-05 13:44:34

标签: apache .htaccess redirect

我通过我的.htaccess

重写了我网站的网址
Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteBase /

RewriteRule ^([a-zA-Z]+)/$ /views/sessions/$1.php [L]
RewriteRule ^blogs/([a-zA-Z]+)/$ /views/blogs/$1.php [L]
RewriteRule ^groups/([a-zA-Z]+)/$ /views/groups/$1.php [L]
RewriteRule ^events/([a-zA-Z]+)/$ /views/events/reports_$1.php [L]

这很有效,当我们输入网址mysite.com/blogs/index/时,我们会mysite.com/views/blogs/index.php

现在我希望您在键入mysite.com/views/account/datas.php时将用户重定向到mysite.com/account/datas/或显示错误404未找到

在另一篇文章中,我被告知这样做:

Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/views/sessions/([a-zA-Z]+).php$ [NC]
RewriteRule ^(.*)/$ views/sessions/$1.php?%{QUERY_STRING}&s=old [L]

RewriteCond %{QUERY_STRING} !^(.*&)?s=old$ [NC]
RewriteRule ^views/sessions/([a-zA-Z]+).php$ $1/ [R=302,NC,L]

RewriteCond %{REQUEST_URI} !^/views/account/([a-zA-Z]+).php$ [NC]
RewriteRule ^account/(.*)/$ views/account/$1.php?%{QUERY_STRING}&s=old [L]

RewriteCond %{QUERY_STRING} !^account/(.*&)?s=old$ [NC]
RewriteRule ^views/account/([a-zA-Z]+).php$ /account/$1/ [R=302,NC,L]

...

但我有这个错误(当我尝试访问mysite.com/account/datas/时):

未找到在此服务器上找不到请求的网址/views/sessions/account/datas.php。

怎么办?

0 个答案:

没有答案