1

我想将所有具有 .html 扩展名的链接重定向到一个 process.php 文件,其中目录+页面名称作为 get 参数。我已经尝试过这些link1 link2解决方案,但它不起作用。

例如

http://localhost/Site/directory1/test1.html
http://localhost/Site/directory2/test2.html

重定向到 process.php 作为

http://localhost/Site/process.php?directory1/test1.html
http://localhost/Site/process.php?directory2/test2.html

我试过这样。

RewriteEngine on
RewriteRule ^/(.*).html /process.php?page=$1

还有这个

RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*/)?([^/]*)\.php$ /process.php?page=$2 [R=301,L]

但它不起作用。

请查看并建议任何可能的方法来做到这一点。

4

3 回答 3

2

试试这个:

RewriteEngine on
RewriteRule ^([^/]*)/(.*\.html) /$1/process.php?page=$2 [R=301,L]
于 2012-12-16T07:30:07.720 回答
1

您的第二个示例与我相信您正在寻找的非常接近。当您应该查找 .html 时,您只需通过一个目录并查找 .php。试试这个。

RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)/(.*)/(.*)\.html$ /Site/process.php?$2/$3 [R=301, L]
于 2012-12-16T07:39:09.710 回答
0

这应该这样做(假设 .htaccess 文件位于Site目录中):

RewriteEngine On
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*?/)?(.*)$ /$1/process.php?page=$2 [R=301,L]
于 2012-12-16T07:32:24.160 回答