Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61784

How do I redirect base url to the specific one in .htaccess?

I would like to redirect my home page to /home. How can I do this?

RewriteRule ^[a-z]{0}$ /home //doesnt work

My whole .htaccess:

Options FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)$ ?site=$1

Example of what do I need to achieve:

blue-world.pl > blue-world.pl/home > blue-world.pl?site=home
blue-world.pl/contact > blue-world.pl?site=contact

Upvotes: 2

Views: 276

Answers (2)

anubhava
anubhava

Reputation: 785266

You may try these rules in your site root .htaccess:

DirectoryIndex index.php index.html
RewriteEngine On

# use ENV:REDIRECT_STATUS="" condition to avoid a redirect loop
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^$ /blue-world.pl/home [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ ?site=$0 [L,QSA]

Upvotes: 1

RavinderSingh13
RavinderSingh13

Reputation: 133538

Based on your shown samples, could you please try following. Please do make sure to clear your browser cache before testing your URLs.

Options FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(home|.*blue-world\.pl)/?$ ?site=$1 [L]

Explanation: Simply checking condition part while rewriting URL(home page) that if uri starts from either with / or without then rewrite it to /home. Also I am using L flag to stop this rule(rewriting rule) here. If this is the ONLY rule in your .htaccess file then you can change above L flag to END flag too. One more point, this considers that your home directory/folder is in root, if this is not the case then change from /home in above to home.

Upvotes: 2

Related Questions