0

我发现这个解决方案可以成功地将 url 从重定向www.domain.com/example.php到,www.domain.com/example但是当子目录很少时我不能做同样的事情,比如:domain.com/dir1/di2/dir3/example.phptodomain.com/dir1/di2/dir3/example

应如何修改此规则以使先前的重定向起作用?

RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]

这是我的 .htaccess

ErrorDocument 404 /misc/404.html

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]

# Forces a trailing slash to be added
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
#RewriteRule (.*)$ /$1/ [R=301,L]

谢谢!

4

1 回答 1

1

http://demo.domain.com/en/index.php带我去http://demo.domain.com/index,它应该带我去http://demo.domain.com/en/index

.htaccess 在 /en/ 目录中

您需要添加一个:

RewriteBase /en/

正下方RewriteEngine on

您可能还需要/en/在重定向规则和条件中添加一个:

RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]

需要是:

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule (.*).php$ /en/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule (.*).html$ /en/$1 [R=301,L]
于 2012-09-25T21:43:09.693 回答