将子文件夹中的页面重定向到新文件夹

时间:2015-10-03 10:00:36

标签: .htaccess redirect

除了位于子目录中的页面之外,所有这些重定向都有效:

  

FR /东西

  

FR /其他-东西

不起作用

RewriteEngine On
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^/?stuff$ http://example.org/more-stuff [R=301,L]
RewriteRule ^/?fr/stuff$ http://example.org/fr/other-stuff [R=301,L]
RewriteRule ^/?es/notice\.php$ http://example.org/es/ [R=301,L,QSD]
RewriteRule ^/?len.php$ http://example.org/es/ [R=301,L,QSD]

这是代码的其余部分

# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

RewriteEngine On
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \.htm
RewriteRule ^(.*)\.htm$ /$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.htm -f  
RewriteRule ^([A-Za-z\-]+)$  $1.htm

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L]

<FILES .htaccess>
order allow,deny 
deny from all
</FILES>

1 个答案:

答案 0 :(得分:1)

/fr/stuff会正确重定向到/fr/stuff/fr/stuff/和目录中的其他内容不会重定向。 要重定向/fr/stuff/,您应该这样做

RewriteRule ^/?fr/stuff/?$ http://example.org/fr/other-stuff [R=301,L]

要重定向子目录,请执行以下操作

RewriteRule ^/?fr/stuff/?(.*)$ http://example.org/fr/other-stuff/$1 [R=301,L]

您应该阅读有关正则表达式的更多信息。