。
这里是我面临的问题:
问题1:
The link below:
https://www.example.com/index.php/gallery
Should redirect to:
https://www.example.com/gallery问题2:
The link below:
https://www.example.com/index.php/profile/juhi/168
Should redirect to:
https://www.example.com/profile/juhi/168问题3:
The link below:
https://www.example.com/index.php
Should redirect to:
https://www.example.com/htaccess代码如下:
RewriteEngine On
# Existing files and directories remain accessible
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
# Redirect the rest
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]发布于 2022-02-16 13:30:54
在/index.php (有效文件)之后的URL-path部分,即.在本例中,/gallery被称为“附加路径名信息”(又名路径信息)。(当mod_rewrite/.htaccess不可用时,许多CMS使用它来路由URL。)
要删除URL的/index.php部分,可以在RewriteEngine指令之后添加以下重定向指令。
# Redirect URLs of the form "/index.php/<URL>" to "/<URL>"
# Also handles "/index.php" only
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index.php(?:/(.*))?$ /$1 [R=301,L]首先使用302 (临时)重定向测试,并且只更改为301 (永久的)--如果这是意图的话--一旦您确认它按预期工作。301系统由浏览器持久地缓存,因此可能会造成测试问题。
撇开:
RewriteRule ^(.*)$ /index.php?/$1 QSA,L
正如我在注释中提到的,您的.htaccess指令正在将请求重写为查询字符串(而不是上面提到的path-info )。这意味着您的页面可以通过第三个URL访问。例如:
/index.php?/gallery
/index.php?/profile/juhi/168我使用的是梦想主机( Dreamhost Webhosting.
FWIW,在您的问题或解决方案中没有提到,是特定于任何特定的网络主机。
https://stackoverflow.com/questions/71138032
复制相似问题