.htaccess子目录重定向,非www到www和参数

时间:2014-08-19 21:14:39

标签: apache .htaccess mod-rewrite redirect

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /qsg/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?Item=$1 [L]
</IfModule>



<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /qsg/

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?Item=$1 [L]
</IfModule>

我试图寻找答案,但一直找不到答案。

我正在尝试重定向: http://example.com/qsg/abcdhttp://www.example.com/qsg/index.php?Item=abcd

当URI出现在URI中时,我可以正常工作。当我删除www时,它会重定向到http://www.example.com/404.shtml

我尝试了上述两种方法,结果相同。我只是无法弄清楚我做错了什么。我已经看到很多其他的例子,这应该有用,但不适合我。我的.htaccess文件中是否有错误是否有可能导致重定向错误?

注意:上述两次重写都不包含在文件中。我已经独立尝试过。

1 个答案:

答案 0 :(得分:0)

给这个人一个机会:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /qsg/

  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /index.php?Item=$1 [L,PT]
</IfModule>