【问题标题】:Htaccess Forward URL from one to anotherHtaccess 将 URL 从一个转发到另一个
【发布时间】:2014-12-22 09:53:11
【问题描述】:

我需要从

转发/重定向域
  http://local.abcxyz.com/be/country/CN/BE

http://local.abcxyz.com/be/country/visum-china/BE

我如何使用 .htaccess 来做到这一点?

我当前的 htaccess 文件是这样的

  RewriteEngine On

    # If the file or directory exists, show it
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+) - [PT,L]
    # Blank queries get sent to the index
    #RewriteRule ^$ index.php [L]
    # All other queries get sent to the index as index.php/whatever
    #RewriteRule ^(.*)$ index.php/$1 [L]

    RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
    RewriteRule ^(.*)$ /be/index.php/$1 [L]

此 htaccess 存在于 be 文件夹中。

【问题讨论】:

    标签: php linux .htaccess redirect


    【解决方案1】:

    您可以在DOCUMENT_ROOT/be/.htaccess 文件中使用此代码:

    RewriteEngine On
    RewriteBase /be/
    
    RewriteRule ^country/CN/BE/?$ country/visum-china/BE [L,NC]
    
    # If the file or directory exists, show it
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
    RewriteRule ^(.+)$ index.php/$1 [L]
    

    假设/country/ 或下面的任何目录中没有.htaccess。

    【讨论】:

    • 该评论对任何人都没有帮助。 Q0。您在浏览器中输入的网址是什么? Q1。这是唯一的 .htaccess 还是你有另一个? Q2。这是这个 .htaccess 中唯一的代码吗?如果您有其他代码,请发布有问题的代码? Q3。上面的.htaccess 的位置是什么? Q4。您确定mod_rewrite.htaccess 已启用吗?
    • 我已在我的问题中添加了所有必需的信息。现有的 htaccess,它的位置也是如此。
    • 我不想重写网址,再次阅读问题我需要将旧网址转发到新网址。新网址运行良好。我需要的是当我输入旧网址时,它会自动重定向/转发到新网址。希望对大家有帮助。
    • @anubhava 我想你还没有看到新的“此 htaccess 存在于 be 文件夹中”
    • Q0。您在浏览器中输入的网址是什么? A0。 local.abcxyx.com/be/country/CN/BE Q1。这是唯一的 .htaccess 还是你有另一个? A1。 root 中有两个目录,be 和 nl,be 和 nl 目录中有 htaccess。 Q2。这是这个 .htaccess 中唯一的代码吗?如果您有其他代码,请发布有问题的代码? A2。 nl 目录中存在相同的 htaccess。 Q3。上面的.htaccess 的位置是什么? A3。 root/be/.htaccess Q4。您是否确保启用了 mod_rewrite 和 .htaccess? A4。我正在使用 CodeIgniter。 Htaccess 和 mod_rewrite 已启用。
    猜你喜欢
    • 2012-07-07
    • 1970-01-01
    • 2013-08-04
    • 2012-12-04
    • 2017-05-18
    • 2022-01-13
    • 2015-08-13
    • 1970-01-01
    • 2013-09-05
    相关资源
    最近更新 更多