Forum Moderators: phranque
I have tried
redirect 301 [mysite.com...] [mysite.com...]
but that doesn't seem to work. Is there any other way to do this? What am I missing? Thanks.
See the documentation and tutorials cited in our Forum Charter [webmasterworld.com] to get started.
Jim
What if the connection is unsecure to begin with (80)?
The problem is that a https page was indexed by google. So if the traffic coming in to the page is from Google, won't it be coming in as http traffic? Or am I thinking about this wrong?
I am trying to do exactly the same thing in my htaccess file because google has awarded a PR rank to some html pages when viewed through https but no PR when viewed through http.
From the documentation, it looks like putting [R=301,L] at the end of the RewriteRule would force an external redirection so Google should transfer the PR from the https to the http page. (Hopefully! )
However, I am having trouble getting my code to work. I have added the following to the end of my htaccess file but I can still view the https page in browser.
RewriteEngine On
RewriteCond %(SERVER_PORT) ^443$
RewriteRule ^(dev/dev-home\.html)?$ [mysite.co.uk...] [R=301,L]
Any ideas?
Thanks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) [%{SERVER_NAME}...] [R=301,L]
If you want to force non-ssl mode for your site use this
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^/?(.*) [%{SERVER_NAME}...] [R=301,L]
Does this mean that modifying the code as shown below will work for me?
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^/?(.*) [%{SERVER_NAME}...] [R=301,L]
What if I have several specific pages that need redirected? What is the most efficient way to do this? Would it be the code below?
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} ^/SPECIFICFILE\.html [NC]
RewriteCond %{REQUEST_URI} ^/SPECIFICFILE2\.html [NC]
RewriteCond %{REQUEST_URI} ^/SPECIFICFILE3\.html [NC]
RewriteRule ^/?(.*) [%{SERVER_NAME}...] [R=301,L]
Similarly, redirecting to %{SERVER_NAME} may give unexpected results if the ServerName is set to example.com, while your preferred hostname is www.example.com or vice-versa. I suggest hard-coding the hostname (domain name) when feasible, or using %{HTTP_HOST} if not. If you do this, then you can use a separate 301 redirect rule for domain canonicalization, without having %{SERVERNAME} force a non-canonical domain unexpectedly.
Jim
Thanks.
[edited by: jdMorgan at 9:19 pm (utc) on Feb. 11, 2009]
[edit reason] No soliciting. Please see Terms of Service. [/edit]
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} ^/EXAMPLE1\.php [NC,OR]
RewriteCond %{REQUEST_URI} ^/EXAMPLE2\.php [NC,OR]
RewriteRule ^/?(.*) http://www.example.com/$1 [R=301,L]
[edited by: jdMorgan at 9:34 pm (utc) on Feb. 11, 2009]
[edit reason] example.com [/edit]
RewriteEngine on
#
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} ^/EXAMPLE1\.php$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/EXAMPLE2\.php$ [NC,OR]
RewriteRule ^/?(.+\.php)$ http://www.example.com/$1 [R=301,L]
Jim
P.S. Nothing personal with the %{HTTPS}. Changing it was just one more thing for me to screw up as far as I was concerned. I like to go the lazy / safe route whenever possible.
Jake
Jim