Chris Nicholson
Chris Nicholson

Reputation: 11

htaccess redirect - too many redirects

I need to rewrite

www.domain.co.uk/store?cat=57

to

www.domain.co.uk/store/57

but I keep getting a 'too many redirects' error. I've got the following in my htaccess:

RewriteCond %{QUERY_STRING} ^cat=([^./]*)$
RewriteRule ^store\.php$ /store/%1? [R=301,L] 
RewriteRule ^store/([^./]+)$ store.php?cat=$1 [L]

The redirect works if I comment out the bottom line, however this then stops my pages loading properly.

Any ideas?

Thanks,

Chris

Upvotes: 1

Views: 203

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

Options -MultiViews
RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+store\?cat=([^\s&]+) [NC]
RewriteRule ^ /store/%1? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^store/([^./]+)/?$ store?cat=$1 [L,QSA,NC]

Upvotes: 2

Related Questions