WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] mod_rewrite to force www in a url? (9 posts)

  1. bradyjfrey
    Member
    Posted 7 years ago #

    I'm digging for answers, and I figured I'd try here - I need to make sure that anyone who pops in http://domain.com gets http://www.domain.com

    I attempted the following in my mod rewrite:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{HTTP_HOST} ^\kamalaspa\.com$
    RewriteRule (.*) http://www.kamalaspa.com/$1 [R=Permanent]

    This does the trick, but it doesn't replace the url with a www version, it only forwards to the index www. If someone types in http://kamalaspa.com/ayurveda/ they get sent to http://www.kamalaspa.com/index.php instead of http://www.kamalaspa.com/ayurveda/

    Any ideas of something I'm missing in my htaccess? Thanks all!

  2. thelazygeisha
    Member
    Posted 7 years ago #

    Can I ask why you're trying to do this?

  3. bradyjfrey
    Member
    Posted 7 years ago #

    Sure, but it's not really answering my question:)

    Because we have an SSL on the www domain, not a wildcard ssl, I need to have it all go www regardless of the access. The ecommerce engine I've worked into wordpress when I launch this, will need to make sure everyones on https://www.kamalaspa.com so that it comes up a valid and certified ssl. If someone types in https://kamalaspa.com the site would still run ssl, but since the cert is not wildcard, it will come up with a validation warning the user that it's made for www not *.kamalaspa.com.

    Wildcard certs are typically double if not more what a regular cert is, and it's not a needed expense in this case.

    So, I need the htaccess to forward in real time to avoid any issue with an invalid message to the user, and an insecure transaction.

  4. bradyjfrey
    Member
    Posted 7 years ago #

  5. AskApache
    Member
    Posted 7 years ago #

    Hey bradyjfrey, I know the askapache author that is a really fantastic article!

    Try this:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    There is also a whole section on using SSL in .htaccess that tackles the same thing as you are dealing with.

  6. bradyjfrey
    Member
    Posted 7 years ago #

    Thanks a bunch cduke250, that should do great, I appreciate it:)!

  7. DanielEK
    Member
    Posted 7 years ago #

    I've tried both, but the solution has caused other problems. I've installed bbpress, but the users that log into Skinplistic WITHOUT the www are not recognized by users that log into bbpress WITH the www. I used the code above to force access via www, however; I noticed this counted multiple hits against my server (I use slimstat). Plus, I think it may be upsetting adsense and the other robots I prey for everyday. ;) I don't know what to do.

  8. AskApache
    Member
    Posted 7 years ago #

    You need to stick with either www or no www, it will take the robots a few months probably before they figure out you only want www.

    robotst.txt and seo with wordpress might be helpful for you to understand the duplicate content problem.

  9. DanielEK
    Member
    Posted 7 years ago #

    Thank you for the response to my question. I'm a little overwhelmed with SEO and the best approach I can take. I decided to removed the code in my .htaccess file because WordPress kept deleting it (I think). I'll take a look at the link...again, thank you. One more thing. I ultimately decided to removed bbpress. I now use simple forum. Very, very nice.

Topic Closed

This topic has been closed to new replies.

About this Topic