【问题标题】:Redirect abc.com to www.abc.com in opencart through .htaccess file in different folders通过不同文件夹中的.htaccess文件将abc.com重定向到opencart中的www.abc.com
【发布时间】:2013-01-17 06:40:31
【问题描述】:

我在两个文件夹中安装了 opencart - 一个是根文件夹,即“public_html/”,一个是“public_html/test/”。两个 opencart 都包含 .htaccess 文件。

'public_html/'文件夹中opencart的.htaccess文件包含以下重写规则:

RewriteBase /
RewriteRule sitemap.xml /new/index.php?route=feed/google_sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^abcd\.co\.in
RewriteRule (.*) http://www.abcd.co.in/$1 [R=301,L]

'public_html/test/'文件夹中opencart的.htaccess文件包含以下重写规则:

RewriteBase /test/
RewriteRule sitemap.xml /new/index.php?route=feed/google_sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

问题是当我打开域 http://abcd.co.in 时,它会重定向到 http://www.abcd.co.in,但是当我打开 http://abcd.co.in/test

它没有重定向

我到 http://www.abcd.co.in/test

【问题讨论】:

    标签: .htaccess redirect opencart


    【解决方案1】:

    如果您点击网址

    http://abcd.co.in/test/
    

    如果您在public_html/test/ 文件夹中有另一个.htaccess 文件,则不计算来自public_html 根文件夹的.htaccess 文件。您应该以这种方式扩展public_html/test/.htaccess

    RewriteBase /test/
    RewriteRule sitemap.xml /new/index.php?route=feed/google_sitemap
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
    RewriteCond %{HTTP_HOST} ^abcd\.co\.in/test/
    RewriteRule (.*) http://www.abcd.co.in/test/$1 [R=301,L]
    

    这应该可以解决问题。

    【讨论】:

    • 严格意义上说,.htaccess 没有被考虑在内。由于目录上方的.htaccess 文件也被应用,因此它被读取,但是由于RewriteBase 不正确,因此在这种情况下它不会被应用。这是正确的解决方法,但是 +1 :)
    【解决方案2】:

    您的重定向规则未应用。 .htaccess 也应该限制在您关联的文件夹中,试试这个,我的头顶:

    RewriteBase /test/
    RewriteRule sitemap.xml /test/index.php?route=feed/google_sitemap
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^?]*) /test/index.php?_route_=$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 2017-07-04
      • 1970-01-01
      • 2013-09-30
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      相关资源
      最近更新 更多