【问题标题】:Redirect all numbered PHP pages to home将所有编号的 PHP 页面重定向到主页
【发布时间】:2017-01-15 09:01:09
【问题描述】:

我要替换的旧 PHP 站点包含一个静态编号的 PHP 文件,用于每个内容分页,即:​​

example.com/pictures-1.php

example.com/pictures-2.php

example.com/pictures-3.php . . .

example.com/pictures-x.php

其中 x 可以是最大为 999 的任何整数。

如何在 .htaccess 中设置重写为 301 将上述所有页面重定向到主页,即https://www.example.com

谢谢。

【问题讨论】:

标签: php .htaccess redirect


【解决方案1】:

做你想做的事情很简单:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/pictures-(\d+).php
RewriteRule ^.*$ http://example.com [L,R=301,NC]

您当然可以扩展它以传递使用以下内容重写的页面:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/pictures-(\d+).php
RewriteRule ^.*$ http://example.com?page=%1 [L,R=301,NC]

http://htaccess.mwl.be/ 有一个方便的小工具可以帮助处理 .htaccess

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 2013-08-17
    • 1970-01-01
    • 2013-01-18
    • 2012-01-02
    • 1970-01-01
    • 2017-01-15
    相关资源
    最近更新 更多