I have this kind of url:
http://www.example.com/index.php?page=contest&contest=this-one-contest
i'm trying to get 2 functioning urls here.
What I'm trying to do is to get this kind of url:
which is already done using this htaccess rewrite rule
RewriteRule ^([a-z_-] )/([a-zA-Z0-9_-] )$ index.php?page=$1 [L,QSA]
RewriteRule ^([a-z_-] )$ index.php?page=$1 [L,QSA]
RewriteRule ^([a-z_-] )/$ index.php?page=$1 [L,QSA]
What I'm trying to do is to get this kind of url in the second url:
I don't Know if this is even possible using htaccess, and i dont want to create a new folder called "contest".
i have tried this already, but it's not still working.
RewriteRule ^([a-z_-] )contest/([a-zA-Z0-9_-] )$ index.php?page=$1&contest=$2 [L,QSA]
RewriteRule ^([a-z_-] )contest/$ index.php?page=$1 [L,QSA]
RewriteRule ^([a-z_-] )contest/$ index.php?page=$1 [L,QSA]
CodePudding user response:
I finally found a work around that works for me, i made lot's of self tweak to @arkascha solution,
RewriteEngine on
RewriteRule ^/?([a-z_-] )/([a-zA-Z0-9_-] )/?$ /index.php?page=$1&contest=$2 [L,QSA]
RewriteRule ^([a-z_-] )/$ index.php?page=$1 [L,QSA]
RewriteRule ^/?contest/?$ /index.php?contest=1$ [L,QSA]
CodePudding user response:
You don't have to use a 2 step approach, you can immediately rewrite this using a very general approach:
RewriteEngine on
RewriteRule ^/?([a-z_-] )/([a-zA-Z0-9_-] )/?$ /index.php?page=$1&contest=$2 [L,QSA]
RewriteRule ^/?([a-z_-] )/?$ /index.php?page=$1 [L,QSA]
This of course assumes that there are no other potential URLs matching the same patterns which you want to handle different ... So if you only want those rules to get applied if the URL starts with /content/
, then that variant should do:
RewriteEngine on
RewriteRule ^/?contest/([a-zA-Z0-9_-] )/?$ /index.php?page=contest&contest=$1 [L,QSA]
RewriteRule ^/?contest/?$ /index.php?page=contest [L,QSA]
And of course if that second parameter also is a literal, fixed one you want to react to, then you can get even more specific:
RewriteEngine on
RewriteRule ^/?contest/this-one-contest/?$ /index.php?page=contest&contest=this-one-contest [L,QSA]
RewriteRule ^/?contest/?$ /index.php?page=contest [L,QSA]