.htaccess 设置301从子目录重定向到特定html文件
我在ubuntu 14.04上运行apache,并尝试设置301重定向。重定向正在工作,但不符合预期。以下是我所拥有的:.htaccess 设置301从子目录重定向到特定html文件,.htaccess,redirect,http-status-code-301,.htaccess,Redirect,Http Status Code 301,我在ubuntu 14.04上运行apache,并尝试设置301重定向。重定向正在工作,但不符合预期。以下是我所拥有的: #REDIRECTS Options +FollowSymLinks RewriteEngine On # REMOVES INDEX.PHP RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Rew
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REMOVES INDEX.PHP
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# REDIRECT SPECIFIC PAGES
Redirect 301 /main http://mikeheavers.com
Redirect 301 /main/ http://mikeheavers.com
Redirect 301 /main/code http://mikeheavers.com/tutorials.html
Redirect 301 /main/code/ http://mikeheavers.com/tutorials.html
前两个重定向301
s工作,但其余的,如/main/code
,尝试重定向到并记录。我做错了什么
更新:请注意,我需要能够重定向包含和不包含尾部斜杠的URL不要将
mod_rewrite
规则与具有redirect
指令的mod_alias
混合使用。使用以下命令:
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REDIRECT SPECIFIC PAGES
RewriteRule ^main/?$ http://mikeheavers.com [L,NC,R=301]
RewriteRule ^main/code/?$ http://mikeheavers.com/tutorials.html [L,NC,R=301]
# REMOVES INDEX.PHP
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
在测试此更改之前,请确保清除浏览器缓存。不要将
mod\u rewrite
规则与具有重定向
指令的mod\u别名
混合使用。使用以下命令:
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REDIRECT SPECIFIC PAGES
RewriteRule ^main/?$ http://mikeheavers.com [L,NC,R=301]
RewriteRule ^main/code/?$ http://mikeheavers.com/tutorials.html [L,NC,R=301]
# REMOVES INDEX.PHP
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
在测试此更改之前,请确保清除浏览器缓存。谢谢-如果我希望能够重定向带有或不带尾部斜杠的url,我该如何处理这种情况?我相信你的例子只允许包含尾随斜杠。谢谢-我该如何处理这样的情况,即我希望能够重定向带有或不带尾随斜杠的url?我相信您的示例只允许包含尾部斜杠。