简体   繁体   中英

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM