htaccess

Redirect using RedirectMatch to language prefix

This is how you can redirect a former indexed path without languagre prefix to a new path with language prefix. In this case i had my old path look like "[domain]/konwledge/[title]" and the new site had a language prefix so the new path should look like "[domain]/en/konwledge/[title]". Add the following in the .htaccess files within the IfModule mod_rewrite.c-tag and modify it.

RedirectMatch 301 ^/knowledge/(.+)$ http://www.zimplicit.se/en/knowledge/$1

Redirect your site to always use www

For make it easy measuring traffic or with sessions cookies for login, you can redirect all calls for example.com to www.example.com by adding the following script to a .htaccess file in root of your site.

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>

Probably you already have an .htaccess file and you just have to uncomment the code and change example.com to your domainname.

How to host the Primary Domain from a subfolder using .htaccess

How do I make a sub directory (or sub folder) act as the public_html for your main domain?


# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirect