.htaccess 301重定向无法处理索引文件

wgx48brx  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(208)

我正在尝试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重定向?

kqqjbcuj

kqqjbcuj1#

请使用显示示例尝试以下.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]

***或者***如果你想写一个通用规则来重写每个不存在的文件到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]

***注意:***一次只能使用其中一个规则集.

相关问题