aleeis
aleeis

Reputation: 61

Mod_rewrite for url with?

I can't find my answer on the other questions here in StackOverflow.. mod_rewrites generator are failing so I don't know how to do that..

I have that urls: http://example.com/?index&category=football

football are dynamic generator by php, so there is many categories. So I want my URL like this: http://example.com/football

How to do that with mod_rewrite? Thank you so much!

Upvotes: 1

Views: 46

Answers (3)

Jon Lin
Jon Lin

Reputation: 143876

Try:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+\?index&category=([^&\ ]+)
RewriteRule ^ /%1? [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /?index&category=$1 [L,QSA]

Upvotes: 0

CDuv
CDuv

Reputation: 2260

This should makes URL http://example.com/football works as if http://example.com/?index&category=football was used:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^/?([^/$]*) /?index&category=$1 [L]

Lines 2 to 5 (from RewriteCond %{REQUEST_FILENAME} -s to RewriteRule ^.*$ - [NC,L]) are optional: they makes any existing file named as a category name (eg. football) be served directly (not using /?index&category=...).

Upvotes: 0

peiman F.
peiman F.

Reputation: 1658

RewriteEngine on
    RewriteRule ^/([a-zA-Z0-9]+)$ /index.php?category=$1
    #RewriteRule ^/([a-zA-Z0-9]+)/$ /index.php?category=$1

Upvotes: 1

Related Questions