I am trying to create SEO friendly URLs for my site and I have come to problem that I can´t solve. I can´t figure out how to setup the rewrite rule so it will show for example like this www.mysite.com/shows/late-night and www.mysite.com/news/title-of-article. Here is my htaccess file:
RewriteEngine on
RewriteRule ^(.*)/([a-z_-]+) index.php?switch=$1&shows=$2 [NC,L]
RewriteRule ^(.*)/([a-z_-]+) index.php?switch=$1&article=$2 [NC,L]
RewriteRule ^shows/$ index.php?switch=shows [NC,L]
RewriteRule ^articles/$ index.php?switch=article [NC,L]
The rewrite rule works if I comment out the first and the third line, but how I do so both will work.
1st and 2nd rule cannot coexist because they are matching same URI pattern. Only first will all the time. Tweak your rules like this:
RewriteEngine on
RewriteRule ^(shows)/([a-z_-]+)/?$ index.php?switch=$1&shows=$2 [NC,L,QSA]
RewriteRule ^(news)/([a-z_-]+)/?$ index.php?switch=$1&article=$2 [NC,L,QSA]
RewriteRule ^(shows|news|articles)/?$ index.php?switch=$1 [NC,L,QSA]
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.