Forum Moderators: phranque

Message Too Old, No Replies

Use htaccess to redirect 1 Wordpress page to SSL

htaccess redirect for SSL

         

JetAviator7

3:56 pm on May 20, 2010 (gmt 0)

10+ Year Member



Hi:

I am brand new to developing websites and I have a website hosted on Hostgator which is the primary domain. There are a number of addon domains under my main domain.

I am trying to have one page on my website redirect to be https and here is the code I have been using:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# Redirect HTTPS requests for non-SSL pages back to HTTP. (Note that shared objects
# such as images on both HTTP and HTTPS pages are excluded from this rule)
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^shop/checkout
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
#
# Redirect HTTP requests for SSL checkout page to HTTPS
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(shop/checkout)$ https://%{HTTP_HOST}/$1 [R=301,L]
#
# Redirect extensionless page requests to remove trailing slash
RewriteRule ^(shop/checkout)/$ http://%{HTTP_HOST}/$1 [R=301,L]
#

The website is a Wordpress blog and the file structure is:

http://www.example.com/shop/checkout/

I tried the above code which I found here but nothing happens. I cleared the cache but still noting happens.

I would appreciate any help.

JetAviator7

[edited by: jdMorgan at 12:47 am (utc) on May 21, 2010]
[edit reason] de-linked, switched to example.com [/edit]

JetAviator7

3:08 pm on May 22, 2010 (gmt 0)

10+ Year Member



Jim:

What if I created a special php page called checkout.php - would it then be easier to redirect for https than with the dynamic Wordpress pages?

In other words, use htaccess to redirect http://example.com/checkout.php to [example.com...]

John

jdMorgan

6:24 pm on May 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, something, somewhere is doing another redirect -- from www.example.com to example.com. I posit that it is your WP setup, since that's what will be invoked for 'most' page requests to your site.

You need to sort out whether your site is to use www.example.com or example.com as its hostname -- there can be only one.

This selection must 'comport' with your SSL Certificate, WP and other CMS setups, Google Webmaster Tools selection, Control Panel settings, all of your on-page links, and with the code in your .htaccess file.

You also need to take into account that as far as Google and the other search engines are concerned, example.com and www.example.com can be two entirely different Web sites. Therefore, you need to take your current search rankings into account -- If your site is strongly ranked and listed with URLs containing the "wrong" hostname for your SSL certificate, then it may not be the case that 'it would be too expensive' to upgrade or replace that cert when faced with the fact that changing all of your URLs from one hostname to another may in fact tank your search rankings for weeks or months... say for up to nine months... possibly seriously affecting your revenue.

So... You need to pick one canonical hostname, and get everything else in agreement with it. That's very easy to do from the start with a new site where you can pick a canonical name up front, build the site using that hostname only, and absolutely prevent (with robots.txt and 301 redirects) any search rankings of non-canonical URLs. But it may not be so easy for an existing site given all of the explicit and implicit costs of correcting built-in problems. :(

Run the numbers, figure out what's going to cost the least in time and money, and then get all of these factors into agreement.

If your site is otherwise all set up for non-www, then simply take all of the "www," and "www\." strings out of the code I posted above.

Jim
This 32 message thread spans 2 pages: 32