.htaccess 将扩展名为none但位于少数目录树级别下的URL重定向301
我发现这个解决方案可以成功地将URL从.htaccess 将扩展名为none但位于少数目录树级别下的URL重定向301,.htaccess,redirect,url-rewriting,.htaccess,Redirect,Url Rewriting,我发现这个解决方案可以成功地将URL从www.domain.com/example.php重定向到www.domain.com/example,但当出现的子目录很少时,我就不能这样做,比如:domain.com/dir1/di2/dir3/example.php到domain.com/dir1/di2/dir3/example 如何修改此规则以使以前的重定向工作 RewriteRule (.*).php$ /$1 [R=301,L] RewriteRule (.*).html$ /$1 [R=3
www.domain.com/example.php
重定向到www.domain.com/example
,但当出现的子目录很少时,我就不能这样做,比如:domain.com/dir1/di2/dir3/example.php
到domain.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]
谢谢大家!
http://demo.domain.com/en/index.php
带我去http://demo.domain.com/index
我应该去http://demo.domain.com/en/index
.htaccess位于/en/目录中
您需要添加一个:
RewriteBase /en/
右下方<代码>重新编写引擎打开
您还可能需要在重定向规则和条件中添加/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]
对于我来说,这些规则可以很好地将
/dir1/di2/dir3/example.php
重定向到/dir1/di2/dir3/example
。http://demo.domain.com/en/index.php
带我去http://demo.domain.com/index
,我将更新帖子以放置我当前的规则。它位于包含最终example.php文件的目录中,你想让我把它也放在public_html/?上吗?你是说它在dir3
中?(或者在第二个示例中,en
?http://demo.domain.com/en/index.php
带我去http://demo.domain.com/index
我应该去http://demo.domain.com/en/index