需要写多参数多的htaccess规则 [英] Need to write multiple htaccess rule with multiple parameters
问题描述
我已经写在htaccess的一些规则,转换PHP扩展HTML和他们的工作很好,但现在我需要编写规则不同的页面相同的参数,但如果我设置相同的规则不同的页面其不工作其重定向同一页面上。
I've some rules already written in htaccess to convert .php extension to HTML and they are working fine but now I need to write rule for different page with same parameter but it if I set same rule for different page its not working its redirecting on same page.
下面是我的htaccess的文件code
Below is my htaccess file code
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]
我已经写的评论每一条规则什么的做的事情。现在目前所有的规则都工作,但是当我添加其他规则也停止工作,所以我只是评论说规则。
I have already written comment on every rule for what its doing. Now currently all rules are working but when I added other rule it stopped working so I just commented that rule.
规则 page.php
是工作,但是当我改变页面到 blog.php的
一些规则的工作,但一些治多参数与 blog.php的
不起作用。
Rule for page.php
is working but when I change page to blog.php
some rules work but some rule with multiple parameter with blog.php
doesn't work.
任何帮助,真是AP preciated
Any help is really appreciated
推荐答案
您可以使用此规则来路由本地主机/ apnaujjain / 1 /博客
到 HTTP://localhost/apnaujjain/blog_detail.php的post_id = 1安培,行动=博客
:
You can use this rule to route localhost/apnaujjain/1/blog
to http://localhost/apnaujjain/blog_detail.php?post_id=1&action=blog
:
RewriteCond %{THE_REQUEST} /blog_detail\.php\?post_id(\d+)&action=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2.html? [R=302,L,NE]
RewriteRule ^(\d+)/(blog)\.html$ blog_detail.php?post_id=$1&action=$2 [L,QSA,NC]
这篇关于需要写多参数多的htaccess规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!