Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: 301 redirect

  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts

    301 redirect

    Hi,

    I'm currently using the following .htaccess code:
    Code:
    RewriteEngine on
    RewriteBase /
    ReWriteRule \.htaccess [F]
    RewriteRule ^([a-zA-Z0-9\/\-]+)$ index.php?url_path=$1
    And I'd like to add a 301 redirect to move all access from http://example.com to http://www.example.com. How can I do it, keeping the current rewrite rule?

    Thanks.

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    add the following just after RewriteBase /

    RewriteCond %{HTTP_HOST} !^www.example.com$
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

    or the following

    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

    Cheers,
    Ess

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a problem with this. I have a website with several sub domains, and using this htaccess code it's impossible to enter subdomains.
    Is there a workaround? Maybe defining several string (subdomains) to exclude?

    Thanks again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •