Search code examples
.htaccessmod-rewriteurl-rewriting

Removing GET parameter in .htaccess and get 2 URLs


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.

  1. What I'm trying to do is to get this kind of URL:

    http://www.example.com/contest

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]
  1. What I'm trying to do is to get this kind of URL in the second URL:

    http://www.example.com/contest/this-one-contest

I don't Know if this is even possible using htaccess, and I don't 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]

Solution

  • 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]