301重定向无法使用索引文件



我正在尝试301将Index.php重定向到另一个URL

这是我的htaccess代码

Options +FollowSymLinks
RewriteEngine on
Redirect 301 /index.php /en1
RewriteRule en1 index.php [NC]

例如,我的域是

www.mysite.com 

我想让它作为工作

www.mysite.com/en1 

在URL栏中显示新的URL,但浏览器显示

The page isn’t redirecting properly

如何修复此301重定向?

使用您显示的示例,请尝试以下.htaccess规则文件。请确保在测试URL之前清除浏览器缓存。

Options +FollowSymLinks
RewriteEngine ON
##Implement http ---> https rules here.
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
##External redirect rules here.
RewriteRule ^/?$ /en5 [R=301,L]
##Internal rewrite to index.php rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^en5/?$ index.php [L]

OR如果您想编写一个通用规则来将每个不存在的文件重写为index.php,请尝试以下操作:

Options +FollowSymLinks
RewriteEngine ON
##Implement http ---> https rules here.
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
##External redirect rules here.
RewriteRule ^/?$ /en5 [R=301,L]
##Internal rewrite to index.php rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

注意:每次只能使用其中一个规则集。

最新更新