1

I'm making a blog like website in PHP. So I have to rewrite my URLs. I have two urls like:

/post.php?name=something&slug=somethingElse

And

/tutorial.php?name=something

So I want to rewrite it like

/post/something/somethingElse

And for the second one

/tutorial/something

So I'm using following lines in .htaccess :

RewriteEngine on

RewriteRule ^(.+)/(.+)[/]?([.+]?)$ $1.php?name=$2&slug=$3

But it isn't working as I expect to.. Tried Google and Stack answers but that didn't help.

anubhava
  • 664,788
  • 59
  • 469
  • 547

1 Answers1

1

Have it this way in your website root .htaccess:

RewriteEngine on

RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.php?name=$2 [L,QSA]

RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ $1.php?name=$2&slug=$3 [L,QSA]

Reference

Community
  • 1
  • 1
anubhava
  • 664,788
  • 59
  • 469
  • 547