Tag Info

Hot answers tagged

8

For your first two rewrites (non-www → www, http → https), the following rule should work: RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !=www.example.com [NC] RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent] Just replace www.example.com with the actual canonical hostname of your site. As for your third ...


2

The problem is that, when you use mod_rewrite in an .htaccess file or a <Directory> section, every successful RewriteRule — even an internal one — causes the request to be restarted internally, and thus the whole rewrite ruleset to be reprocessed. Thus, what's happening is that, when the user visits /page, your internal RewriteRule matches ...


2

I asked this same question on StackOverflow. To get it to work properly, you have to use environment variables: RewriteRule ^page$ /page.html [L,E=LOOP:1] RewriteCond %{ENV:REDIRECT_LOOP} !1 RewriteRule ^page.html$ /page [R=301,L] This is because mod_rewrite does multiple passes through your rules. During the first pass, it sets the environment ...


1

What is the purpose of the redirect? The 301 Canonical The purpose of your redirect is to assure a canonical domain name. As such, the appropriate HTTP response is a 301. By default, many browsers will cache this indefinitely unless you specify a Cache-Control header. The 302 Confusion In the Google reference you provide, they are talking about landing ...


1

The type of redirect you are using is not the problem. 301 redirects are cacheable. In fact they are extremely hard to cache bust. 301 means "permanent" and browsers are very likely to cache 301 redirects with no way with the server to undo one that is already cached. 302 redirects are generally not cached by default unless other headers indicate that ...


1

ok I figured it out RewriteRule ^xy(.*)$ /xy/$1 [R=301,L]


1

Try this: RewriteCond %{REQUEST_URI} !^/xy/ [NC] RewriteCond %{REQUEST_URI} ^/xy(.*)$ [NC] RewriteRule .* http://www.example.org/xy/%1.html [R=301,L] I think should do it. Please let me know and I can update the answer.



Only top voted, non community-wiki answers of a minimum length are eligible