需要帮助编写htaccess规则

时间:2015-03-24 11:32:25

标签: .htaccess

目前我的localhost网址与localhost/apnaujjain/page.php?page_id=1&action=contacts

类似

现在我想写一条规则,这样当我转到上面的网址时,它只会重写网址,如localhost/apnaujjain/contacts.html

看到它应该将.php转换为.html而不影响页面内容。

到目前为止,我已经尝试了

Options +FollowSymLinks -MultiViews
RewriteEngine on
#RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.php?page_id=1$&action=2$
RewriteRule ^(.*)\.php $2.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]

但它没有用。

1 个答案:

答案 0 :(得分:1)

您可以在/apnaujjain/.htaccess

中使用此代码
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/

# redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to
# localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2.html? [R=301,L]

RewriteRule ^([^/]+)/([^.]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
相关问题