简体   繁体   中英

htaccess RewriteRule isn't working as expected

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM