如何编写条件.htaccess文件

时间:2015-04-20 05:48:58

标签: php regex .htaccess

我的网站的每个网页都有不同的网址, Seo 变量,页面点击网址变为

index.php?seo=home
rates.php?seo=rates
reservation.php?seo=reservation

现在我想将网址转换为此

agnow.us/rates
agnow.us/information
agnow.us/reservation

这是我的.htaccess文件。

选项+ SymLinksIfOwnerMatch -Multiviews RewriteEngine on RewriteBase /

RewriteCond %{THE_REQUEST} \s/+rates\.php\?seo=([^\s&]+) [NC]
RewriteRule ^ /%1? [L,R=301]

RewriteRule ^/(.*)$ rates.php?seo=$1 [L,NC,QSA]

1 个答案:

答案 0 :(得分:1)

您可以在root .htaccess中使用此代码:

Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+rates\.php\?seo=([^\s&]+) [NC]
RewriteRule ^ /%1? [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ rates.php?seo=$1 [L,NC,QSA]