valesp
By:
valesp

.Htaccess file redirects configuration

March 29, 2016 1.3k views
Apache Server Optimization

Hi guys,

Just configured my .htaccess file on apache server for redirect 301, from www to none, etc. But it seems to be not working at all...Anybody have faced with the same issue?!

1 Answer

Hey there,

It's hard to say without seeing your exact .htaccess file, but this tutorial covers the entire process. I'd recommend reviewing the tutorial and if you have a question at any point just reply here :)

Happy coding,

Jon Schwenn
Platform Support Specialist
DigitalOcean

This tutorial will show you how to redirect a www URL to non-www, e.g. `www.example.com` to `example.com`, with Apache on Ubuntu 14.04. We will also show you how to redirect in the other direction, from a non-www URL to www.
  • Hi Jon,

    Here you see the mentioned .htaccess file, but no one of the code below works. I guess smth wrong on the host side, could it be ?!

    Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working

    Redirect /index.html/

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.sample\.com$ [NC]
    RewriteRule ^(.*)$ http://sample.com/$1 [R=301,L]

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUESTFILENAME} !-d
    RewriteCond %{REQUEST
    URI} ^(.+)/$
    RewriteRule ^(.+)/$ /$1 [R=301,L]

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\ HTTP
    RewriteRule ^index.php$ http://sample.com/ [R=301,L]

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP
    RewriteRule ^index.php$ http://sample.com/ [R=301,L]

Have another answer? Share your knowledge.