Mobile app version of vmapp.org
Login or Join
XinRu657

: Htaccess with regex not working properly! I can't seem to get the regex in my htaccess redirect working: RewriteRule [./:_a-zA-Z0-9]*/(web-browse(r|rs)-benchmarks)[a-zA-Z0-9-/.:?=]*(|html) /web-browser-benchmarks-firefox-chrome/

@XinRu657

Posted in: #301Redirect #Htaccess #Redirects

I can't seem to get the regex in my htaccess redirect working:

RewriteRule [./:_a-zA-Z0-9]*/(web-browse(r|rs)-benchmarks)[a-zA-Z0-9-/.:?=]*(|html) /web-browser-benchmarks-firefox-chrome/ [R=301,L]

Even .+(web-browser-benchmarks-firefox-chrome).+ won't work

I'm getting this error in chrome:


The domain.org page isn’t working

domain.org redirected you too many times. ERR_TOO_MANY_REDIRECTS

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @XinRu657

1 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

What seems to be happening, is your rule is being matched and then apache is sending a 301 redirect response telling the browser to generate a new request for

/web-browser-benchmarks-firefox-chrome/


Chrome is generating this request - as instructed, but when your webserver see's this new request - your rule is matching that request too - again telling chrome to generate another request for /web-browser-benchmarks-firefox-chrome/ resulting in an infinite loop.
You can check with:

$ curl -I domain.org/web-browser-benchmarks-firefox-chrome/


You will probably see something like:

HTTP/1.1 301
Server: apache
Location: domain.org/web-browser-benchmarks-firefox-chrome/ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this is telling chrome/curl/etc to re-request the page it just requested
Date: Thu, 18 Feb 2016 08:56:02 GMT
[...]


You can try break the loop by with a conditional check - so assuming that
domain.org/web-browser-benchmarks-firefox-chrome/

is the actual URL you want to serve, and your current rule uses [R=301,L] so Im assuming a 301 external redirect is what you want.

# this RewriteCond tells apache if this URL is requested, thats the URL we want
# so serve it instead of rewriting it.
RewriteCond "%{REQUEST_URI}" !^/web-browser-benchmarks-firefox-chrome/
RewriteRule [./:_a-zA-Z0-9]*/(web-browse(r|rs)-benchmarks)[a-zA-Z0-9-/.:?=]*(|html) /web-browser-benchmarks-firefox-chrome/ [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme