.htaccess - Correct RegEx to avoid infinte loop using RewriteRule to redirect 301 -


i trying tell server redirect following requests:

http://example.es http://example.es/ http://example.es/es http://example.es/es/ http://www.example.es http://www.example.es/ http://www.example.es/es 

to page:

http://www.example.es/es/ 

in order have following in .htaccess

#rewriteengine on    # turn on rewriting engine rewritebase / rewritecond %{http_host} ^(\.?example\.es(/|/es|/es/)?|www\.?example\.es(/|/es)?)$ [nc] rewriterule ^(.*)$ http://www.example.es/es/ [r=301,l] 

the problem causes infinite redirects since wanted url http://www.example.com/es/ has http_host string within. thing cannot find accurate regular expression avoid problem.

the rest of .htaccess goes follows:

php_flag register_long_arrays on php_flag register_globals on addoutputfilterbytype deflate text/html text/plain text/xml text/css javascript application/javascript expiresactive on expiresbytype text/css "access plus 1 years" expiresbytype image/png "access plus 1 years" expiresbytype application/javascript "access plus 1 years"  header set connection keep-alive 

help very appreciated!

cheers!

afaik apache's rewrite uses perl regex, negative-lookaheads supported. can use 1 avoid matching http://www.example.com/es/ itself. try:

^(\.?example\.com(/|/es|/es/)?|www\.?example\.com(/|/es(?!/))?)$


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -