【发布时间】: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