With firebug, grab the HTTP headers.. firefox gives 200 OK status.
Firebug in Chrome, tells me it is a 301 redirect.
The problem is that the page is not supposed to redirect. The htaccess only forces WWW..
Help!
That kind of .htaccess rule works by redirecting the request! The R=301 at the end means "redirect, sending http status 301"
btw the rule you have will redirect www.example.com to example.com. Perhaps you want the opposite:
RewriteCond %{HTTP_HOST} ^website.com [NC]
RewriteRule ^(.*)$ www.website.com/$1 [L,R=301]
Related
I know this has been asked several times, but I have checked a lot of the other answers and still couldn't solve my problem.
Let's assume my website is example.com
I want to redirect all http address to https, and also redirect all example.com visitors to example.com/main
This is what I tried:
RewriteEngine On
RewriteRule ^(.*)$ https://www.example.com/main/$1 [R,L]
It sort of works, but there are some issues.
If I type www.example.com/main or example.com/main it goes to the http site, instead of the https. Why is that?
Also, if I type example.com/works/01 it becomes https://www.example.com/main/works/01. It adds an extra 'main' folder in.
How to fix this problem?
You need to check if the request is comming from http URL scheme and then redirect that request to a secure connection
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/main/$1 [R,L]
Got a .htaccess file that is working correctly with the following
Redirect 301 /secure/test/ http://ww2.example.com/secure/test/
Redirect 301 /test/ http://ww2.example.com/test/
Redirect 301 /submission/ http://ww2.example.com/submission/
That will happily redirect:
http://example.com/secure/test/login.aspx
However if someone comes in on
https://example.com/secure/test/login.aspx
It doesn't work, how to I also redirect all https traffic to follow the rules above?
You will need to change your mod_alias redirects to use mod_rewrite instead.
For example, in .htaccess:
RewriteEngine
RewriteCond %{SERVER_PROTOCOL} ^http(s?) [NC]
RewriteRule ^(secure/test/.*) http%1://ww2.example.com/$1 [R=302,L]
This redirects http to http and https to https. (Are you sure you don't always want to redirect to https instead?)
The %1 backreference matches the s in the SERVER_PROTOCOL (if present).
Clear your browser cache before testing (301 redirects are cached), and change the 302 (temporary) redirect to 301 (permanent) when you are sure it's working OK.
I'm struggling to see why this rule won't work on the site.
The old url was /mobile/article/site/article-name and the new url is just /article/article-name
The rule is
RewriteRule ^mobile/article/tgc/(.*)$ /article/$1 [L,R=301]
Testing against http://htaccess.madewithlove.be/ with the whole htaccess file tells us
This rule was met, the new url is http://site.dev/article/article-name
Test are stopped, because of the R in your RewriteRule options. A redirect will be made with status code 301
but when we try hit http://site.dev/mobile/article/site/article-name in the browser, we get a 404 rather than a redirect.
What's even more curious is that we have the same kind of rule for another url
RewriteRule ^resources/a/(.*)$ http://resources.site.dev/library/$1 [L,R=301]
Which comes after our troubled redirect and it works just peachy.
What are we missing?
Keep your rule as this:
RewriteRule ^mobile/article/site/(.*)$ /article/$1 [L,NC,R=301]
So I have the following .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://www.google.com [NC]
RewriteRule ^dir/file.html http://domain.tld/dir/index.html [L,R=302]
When I visit my site by clicking on it in the Google SERP it showsme dir/file.html. If I hit F5 to refresh it does the redirect. But then if I try to go to http://domain.tld/dir/file.html from dir/index.html I can't. I get 302 redirected, once again, to the index.
It's as though the browser is caching the 302 redirect when the only redirects it should be capturing are 301 redirects.
Any ideas?
I'm using htaccess rewrite engine to make urls look nice,
from www.mysite.com/index.php?pag=home to www.mysite.com/pag/home
it works fine with this rule
RewriteRule ^pag/([^/]+)$ index.php?pag=$1 [L,QSA,NC]
but when I go to www.mysite.com it redirects me to www.mysite.com/index.php
is there a way to redirect to www.mysite.com/pag/home?
I tried
redirect 301 /index.php http://www.mysite.com/pag/home
but when i try to go to www.mysite.com the browser gives my "page do not exsist error"
This is the rule that Drupal uses to make it's pretty urls, yours should be extremely similar:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Your rule only matches on urls that have pag in them, but you're really wanting to hit every url.
the problem was in this redirect rule
redirect 301 /index.htm http://www.mysite.com/index.php