Home > front end >  .htaccess rewrite rule to subfolder if is specific folder
.htaccess rewrite rule to subfolder if is specific folder

Time:04-14

I need some help with my .htaccess file specifically with a rewrite rule

My directory structure:

root
├── plans
│   │── .htaccess
│   │── app 
│   └── public
└── Wordpress

The result what I want:

If the user goes to the directory https://localhost:8888/plans/ The htaccess file rewrite this to the subfolder public (https://localhost:8888/plans/public)

What I tried so far

RewriteEngine On

RewriteRule ^$ /public/ [L]

This gives my a 404 error not found.

Is this possible and how can I do this?

CodePudding user response:

You may use this rule in plans/.htaccess:

RewriteEngine On

RewriteRule ^(?!public/)(.*) public/$1 [L,NC]

This will rewrite all paths in /plans/ to /plans/public/. (?!public/) is a negative lookahead to stop rewrite if URI is already /plans/public/.

  • Related