ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

.htaccess redirect and domain.com -> www.domain.com redirect

August 23, 2011 11:43am

Subscribe [5]
  • #1 / Aug 23, 2011 11:43am

    SwitchDev

    43 posts

    I am trying to use the .htaccess file to remove the index.php from the domain. I have the following in the file and it works fine.

    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    However I am also trying to forward anyone who reaches the site at https://domain.com to forward them to https://www.domain.com. I have the following in place, but I am having some issues with it.

    <IfModule mod_rewrite.c>
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    RewriteCond %{HTTP_HOST} (.+)$ [NC]
    RewriteRule ^(.*)$ <a href="http://www.%1/$1">http://www.%1/$1</a> [R=301,L]
    </IfModule>

    For the most part it is working. The only issue is when navigating to a sub page the index.php gets added. Example navigating to https://domain.com/sub sends you to https://www.domain.com/index.php?/sub.

    The page still works fine, only now it’s even uglier. I am not super familiar with the Rewrite stuff so any help would be appreciated. I am using the HTML5 Boilerplate if anyone is familiar with that.

    thanks

  • #2 / Aug 23, 2011 10:00pm

    Dan Decker

    7338 posts

    yankeyhotel,

    Unfortunately, we are only able to support .htaccess as outlined here. However, I will move this into Community Help and perhaps those with better knowledge of more advance rewrite rules can offer some advice.

    Cheers,

  • #3 / Aug 24, 2011 11:47am

    SwitchDev

    43 posts

    sounds good, thought that might be the case.

    everyone thanks for the help!

  • #4 / Aug 24, 2011 12:16pm

    johndwells

    94 posts

    Hi yankeyhotel,

    I tend to put this before the EE rewrite rules:

    RewriteCond %{HTTP_HOST} ^domain.tld$
    RewriteRule (.*) <a href="http://www.domain.tld/$1">http://www.domain.tld/$1</a> [R=301,L]

    Customise the “domain.tld” to your domain, and that has always worked for me.

    Cheers,
    John

  • #5 / Aug 24, 2011 12:18pm

    Tad Ward

    41 posts

    yankeyhotel,

    try this in your .htaccess file:

    RewriteCond %{HTTP_HOST} !^www\.DOMAINNAME\.com$ [NC]
    RewriteRule ^(.*)$ <a href="http://www.domainname.com/$1">http://www.domainname.com/$1</a> [R=301,L]
  • #6 / Aug 24, 2011 12:19pm

    Tristan Blease

    3 posts

    Is the HTTPS redirect below the EE redirect instructions? Looks like it’s doing the EE rewrite first and then doing the 301. Try reversing the order?

  • #7 / Aug 24, 2011 12:31pm

    SwitchDev

    43 posts

    I love this community! Thanks everyone for the help everything seems to be working. I think it was the reordering that did it!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases