【问题标题】:.htaccess subdirectory redirect with non www to www and parameters.htaccess 子目录重定向与非 www 到 www 和参数
【发布时间】:2014-08-19 21:14:38
【问题描述】:
<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 中存在 www 时,我可以正常工作。当我删除 www 时,它会重定向到 http://www.example.com/404.shtml

我已经尝试了上述两种方法,结果都相同。我只是无法弄清楚我做错了什么。我已经看到了很多其他应该可以使用的示例,但不适用于我。我的 .htaccess 文件有问题吗?是否有其他原因导致重定向错误?

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

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    试一试:

    <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>
    

    【讨论】:

    • 这仍将我发送到example.com/404.shtml 是否有可能是其他原因造成的?
    • 如果有它会是 htaccess 冲突......我正在努力解决这个问题,它在我的端工作得很好,这很奇怪。
    • 我认为这可能是另一个 htaccess 冲突。但是,我检查了根目录中的主 htaccess 文件,似乎没有什么突出的。
    • 将 www 部分添加到主 htaccess
    猜你喜欢
    • 2014-11-24
    • 1970-01-01
    • 2011-04-12
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 2012-11-16
    相关资源
    最近更新 更多