设置从子目录到特定 html 文件的 301 重定向
set up 301 redirect from subdirectory to specific html file
我在 ubuntu 14.04 上 运行 apache 并尝试设置 301 重定向。重定向有效,但未达到预期。这是我拥有的:
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REMOVES INDEX.PHP
RewriteCond !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [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
前两个 redirect 301
有效,但其余的 /main/code
尝试重定向到 http://mikeheavers.com/code and note http://mikeheavers.com/tutorials.html。我做错了什么?
更新:请注意,我需要能够重定向包含和不包含尾部斜杠的网址
不要将 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 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [L]
确保在测试此更改之前清除浏览器缓存。
我在 ubuntu 14.04 上 运行 apache 并尝试设置 301 重定向。重定向有效,但未达到预期。这是我拥有的:
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REMOVES INDEX.PHP
RewriteCond !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [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
前两个 redirect 301
有效,但其余的 /main/code
尝试重定向到 http://mikeheavers.com/code and note http://mikeheavers.com/tutorials.html。我做错了什么?
更新:请注意,我需要能够重定向包含和不包含尾部斜杠的网址
不要将 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 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/ [L]
确保在测试此更改之前清除浏览器缓存。