1

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!

Mekey Salaria
  • 1,093
  • 9
  • 24

1 Answers1

0

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]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I'm afraid. It is not working for me. Can you tell me for what purpose we added [L,NC,QSA] ? I believe QSA is somewhat related to Query String. How about L? – Mekey Salaria Jul 23 '13 at 10:26
  • 1
    L is for Last Rule, NS is for no case comparison and QSA is for (existing) query string append. You just need L flag but as I wrote make sure .htaccess and mod_rewrite are enabled through Apache config. If they are enabled then post your complete .htaccess within your question. – anubhava Jul 23 '13 at 10:29
  • Hey thank you so much. I added [L...] my rule and it is working perfect. My bad, I was trying http://localhost/series/1/1/Introduction%20to%20HTML.html Instead of http://localhost/1/1/Introduction%20to%20HTML.html Now it works perfect. Thank You!. – Mekey Salaria Jul 23 '13 at 10:32