【问题标题】:php url rewrite moving page from old fold to new foldphp url重写将页面从旧折叠移动到新折叠
【发布时间】:2014-08-08 19:08:08
【问题描述】:

在将页面从旧折叠移动到新折叠时遇到了一些问题。

我以前的.htacess/var/www/html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^items/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

现在我更新我的网站。新建文件夹/var/www/html/2014

然后是另一个sub .htacess 在`/var/www/html/2014

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /2014/
RewriteRule ^phone/products/(\d+)/(.*)?$ phone/products.php?number=$1&name=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
</IfModule>

现在我想将www.example.com/items/products/1234/iphone-5c 移动到www.example.com/2014/phone/products/1234/iphone-5c

我尝试在旧页面items/products.php添加以下代码

<?php
header("Status: 301 Moved Permanently");
header('http://www.example.com/2014/phone/products/'.$_GET['number'].'/'.$_GET['name']);
exit;
?>

错误日志:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

我在/var/www/html中修改old .htacess

RewriteRule ^item/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [QSA,L]
=>
RewriteRule ^2014/phone/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [QSA,L,R=301]

重定向到404 page,如何正确操作?谢谢

【问题讨论】:

    标签: php .htaccess mod-rewrite redirect header


    【解决方案1】:

    将此保存在/var/www/html/.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^items/products/(\d+)/(.*)?$ 2014/phone/products.php?number=$1&name=$2 [QSA,L]
    </IfModule>
    

    将此保存在/var/www/html/2014/.htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /2014/
    RewriteRule ^phone/products/(\d+)/(.*)?$ phone/products.php?number=$1&name=$2 [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) $1.php [L]
    </IfModule>
    

    删除您的 PHP 代码以进行重定向。在新的浏览器中测试它。

    【讨论】:

      【解决方案2】:

      由于您使用的是同一个 PHP 文件,因此您似乎没有区分请求的 URL,而是将 每个 请求发送到:

      <?php
      header("Status: 301 Moved Permanently");
      header('http://www.example.com/2014/phone/products/'.$_GET['number'].'/'.$_GET['name']);
      exit;
      ?>
      

      检查您的重定向逻辑,以仅通过上述代码发送使用旧 URL 的页面。

      【讨论】:

      • 我正在使用 wp。我确定我使用的是相同的 PHP。我在 items/products.php 中有 echo 'http://www.example.com/2014/phone/products/'.$_GET['number'].'/'.$_GET['name']; 和旧代码。比页面显示http://www.example.com/2014/phone/products/1234/iphone-5c鼠标右键在新的浏览器选项卡中打开,它显示得很好。但是在标题代码中发生了变化,在 htacess 中出现警告。
      猜你喜欢
      • 2017-06-03
      • 2019-04-13
      • 2017-06-15
      • 1970-01-01
      • 2015-10-01
      • 2016-02-28
      • 2021-05-29
      • 2014-04-29
      • 1970-01-01
      相关资源
      最近更新 更多