Rewrite URL with three dynamic parameters

我只是一个虾纸丫 提交于 2019-12-11 10:51:26

问题


I am working on my website where URL is something like:

http://mywebsite.com/series.php?sid=1&part=1&name=Introduction%20to%20HTML

I have tried a rule in my htaccess which is:

RewriteRule ^([^/]+)/([^/]+)/([^\.]+)\.html$ /series.php?sid=$1&part=$2&name=$3

In order to rewrite URL in form of:

http://mywebsite.com/1/1/Introduction to html.html

Unfortunately, it is not working for me.

Please someone help me in sorting out the issue. I would also love it if someone makes me understand how it worked. I'm newbie for .htaccess. In above rule, I can see three different parts like:

1st part: ^([^/]+)
2nd Part: ([^/]+)
3rd part: ([^\.]+)\.html$

These three parts are separated by backslash. How they work and how can I utilize the same Rewrite URL form for more than 3 let say 4 or 5 parameters and less than 3 like 2 parameters?

Thank You!


回答1:


Your rule is correct, just add L flag to end the rule and make sure .htaccess and mod_rewrite are enabled through Apache config.

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteRule ^([^/]+)/([^/]+)/([^\.]+)\.html$ /series.php?sid=$1&part=$2&name=$3 [L,NC,QSA]


来源:https://stackoverflow.com/questions/17806971/rewrite-url-with-three-dynamic-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!