.htaccess url rewrite - remove .php - 添加尾部斜杠 - 并缩短查询字符串

时间:2013-08-25 00:32:50

标签: php apache .htaccess mod-rewrite

我最近一直在使用CMS,并希望删除.php添加尾部斜杠并删除查询字符串,例如page.php?page =联系页面/联系

到目前为止,我的.htaccess文件看起来像这样:

# This is a .htaccess file
# Don't edit it.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php\?page=([^&\s]+)&?
RewriteRule (.*)\.php$ /$1/%1/? [L,R=301]

RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]

除此之外,我无法弄清楚如何缩短查询字符串。我环顾四周,找不到任何其他特定的问题......

提前谢谢。

1 个答案:

答案 0 :(得分:1)

我误解了你。我只是需要截断查询字符串。这将从查询字符串中提取page参数值并将其附加到URL。 ?像以前一样截断查询字符串。

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php\?page=([^&\s]+)&?
RewriteRule (.*)\.php$ /$1/%1/? [L,R=301]

RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]