我已经在htaccess中编写了一些规则,将.php扩展名转换为HTML并且它们工作正常但现在我需要为具有相同参数的不同页面编写规则但是如果我为不同的页面设置相同的规则则不能正常工作它在同一页面上重定向。
以下是我的htaccess文件代码
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/
# add everything for webservice/...
RewriteRule ^webservice(/.*)?$ - [L,NC]
#redirect localhost/apnaujjain/blog.php?page_id=1&post_id=1&action=blog to localhost/apnaujjain/1/1/blog.html
#RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
#RewriteRule . %1/%2/%3.html? [R=301,L]
#RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ blog.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]
#redirect localhost/apnaujjain/page.php?page_id=1&album_id=1&action=contacts to localhost/apnaujjain/1/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2/%3.html? [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ page.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]
#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&]+)\s [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^./]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
#redirect localhost/apnaujjain/contacts.php to localhost/apnaujjain/contacts.html
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php\s [NC]
#RewriteRule ^(admin|webservice)($|/) - [L]
RewriteRule !^admin/ /%1.html [NC,R=302,L,NE]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
我已经就每件规则的评论做了评论。现在所有规则都在运行,但是当我添加其他规则时它停止工作,所以我只是评论了这个规则。
page.php
的规则正在运行,但是当我将页面更改为blog.php
时,某些规则可以正常工作,但是带有blog.php
的多个参数的某些规则不起作用。
非常感谢任何帮助
答案 0 :(得分:1)
您可以使用此规则将(2 # #y) $ (1 j. #y) # y
路由到localhost/apnaujjain/1/blog
:
http://localhost/apnaujjain/blog_detail.php?post_id=1&action=blog