问题
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