Hawkar Oghiz
Hawkar Oghiz

Reputation: 35

Regular expression for htaccess URL rewrite

hiii ,

I want to rewrite the directory www.mysite.com/index.php?category=news to www.mysite.com/news I write this code but its doesn't work anyone can help, please thanks for help

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

Thanks for all who answered my question , all the codes are work when i try to write www.mysite.com/news , but I mean when i click on a link "a href='index.php?category=news'"link"/a" I want to be rewrite to www.mysite.com/news immediately

Upvotes: 0

Views: 93

Answers (4)

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

RewriteRule ^(news|or|some|other|category)$ index.php?category=$1 [QSA,NC,L]

Upvotes: 0

Ameer
Ameer

Reputation: 771

try this

Options +FollowSymLinks
RewriteEngine on
RewriteRule news/ index.php?category=news
RewriteRule news index.php?category=news

Upvotes: 0

Phil
Phil

Reputation: 165059

Just to confirm, the pattern you want to match is all letters, numbers, hyphens and forward-slashes, right?

If so, try this

RewriteRule ^([a-zA-Z0-9/-]+)$ index.php?category=$1 [QSA,L]

I think the problem may have been your ordering of the hyphen and forward-slash in the character class expression. To match hyphens, they should appear first or last in the set of characters.

Upvotes: 1

JoLoCo
JoLoCo

Reputation: 1375

Does this work?

RewriteBase /
RewriteRule (.*) index.php?category=$1 [QSA,NC,L]

Upvotes: 0

Related Questions