将所有编号的PHP页面重定向到主页

时间:2016-09-07 15:22:29

标签: php .htaccess redirect

我正在替换的旧版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

感谢。

1 个答案:

答案 0 :(得分: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
相关问题