Wai Yan Hein
Wai Yan Hein

Reputation: 14791

SilverStripe .htaccess redirecting to different page without changing the URL is not working

I am working on a SilverStripe 4 project. I am trying to show a different page when the user visits the home page without changing the URL. I am configuring it in the .htaccess. But it is not working.

Following is my .htaccess file under the root folder of the project

RewriteEngine On
RewriteRule ^(.*)$ public/$1
RewriteRule ^/ /welcome [P]

When I visit the home page, it is still showing the home page. What is missing in my code and how can I fix it?

Upvotes: 0

Views: 126

Answers (1)

anubhava
anubhava

Reputation: 784998

  1. Change order of your rules to keep match-all rule at bottom
  2. Fix your match pattern to make sure it matches home page only
  3. Use L (last) flag instead of P (proxy) flag.
  4. Also add a negative lookahead in public rule to avoid looping.

You may use these rules in site root .htaccess:

RewriteEngine On

RewriteRule ^/?$ welcome [L]

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(?!public/)(.+)$ public/$1 [L,NC]

Upvotes: 1

Related Questions