【问题标题】:How to remove "index.php?" from HTACCESS [duplicate]如何删除“index.php”?来自 HTACCESS [重复]
【发布时间】:2014-07-27 21:07:21
【问题描述】:

我有这样的网址:

www.site.com/index.php?/genero/aventura/av/

但我希望这是我的新网址:

site.com/genero/aventura/av/

我使用了以下代码:

<IfModule mod_rewrite.c>RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.site.com/$ [NC]
RewriteRule ^index.php\?/(.*)$ site.com/$1 [R=301,L]
</IfModule>

但只返回我:site.com/index.php?/genero/aventura/av/

这是我最新的完整版:

RewriteEngine on
#RewriteCond $1 !^(index\.php|ver_capitulo\.html|google3436eb8eea8b8d6e\.html|BingSiteAuth\.xml |portadas|public|mp3|css|favicon\.ico|js|plantilla|i|swf|plugins|player\.swf|robots\.txt)
RewriteCond $1 !^(index\.php|public|css|js|i|feed|portadas|robots\.txt|BingSiteAuth\.xml|plugins|i|mp3|favicon\.ico|pluginslist\.xml|google3436eb8eea8b8d6e\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]

#DirectoryIndex index.php
#RewriteCond %{THE_REQUEST} http://www.page.com/index\.php [NC]
#RewriteRule ^(.*?)index\.php$ http://page.com/$1 [L,R=301,NC,NE]

#DirectoryIndex index.php
#RewriteEngine On

感谢阅读。

【问题讨论】:

  • Host: 名称不包含尾部斜杠。并且查询字符串不能用作 RewriteRule 路径,而只能用作 in %{QUERY_STRING}。顺便说一句,您的规则仅重定向到预期的新 URL 方案。除非您还处理传入的规范化路径,否则不会调用 index.php 处理程序脚本。

标签: php apache .htaccess mod-rewrite


【解决方案1】:

用这个替换你的规则:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|public|css|js|i|feed|portadas|robots\.txt|BingSiteAuth\.xml|plugins|i|mp3|favicon\.ico|pluginslist\.xml|google3436eb8eea8b8d6e\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]

【讨论】:

  • 我尝试以这种方式包含 www: DirectoryIndex index.php RewriteEngine On RewriteCond %{THE_REQUEST} www.page.com/index\.php [NC] RewriteRule ^(.*? )index\.php$ page.com/$1 [L,R=301,NC,NE] 但仍未解决
  • 你为什么在RewriteCond %{THE_REQUEST} www.page.com/index\.php而不是我建议的?
  • 您也使用了您的建议,并给了我相同的结果,请尝试删除 www。还有index.php?因为当我尝试删除 www.我只是去 index.php?,我同时删除(www 和 index.php?)。
  • 在您的问题中粘贴最新且完整的 .htaccess。
  • 现在可以看到上面的代码了,我贴出来的部分
猜你喜欢
  • 1970-01-01
  • 2013-01-08
  • 2013-09-15
  • 1970-01-01
  • 2012-04-03
  • 2019-04-06
  • 1970-01-01
  • 1970-01-01
  • 2016-05-13
相关资源
最近更新 更多