Blue
Blue

Reputation: 259

.htaccess to redirect to subfolder

Im trying to do the following: if I go to www.example.com/panel -> i want to open index.php in folder panel, if I go to www.example.com/panel/somehing - i want it to translate this to www.example.com/panel/index.php?content=something

Now I've tried all sort of possible solutions here that includes redirecting to sub-folder like

RewriteCond %{REQUEST_URI} !^/subfolder/public/ [NC]
RewriteRule ^(.*)$ subfolder/public/$1 [L]

but this completely overrides my main index.php and redirects everything to sub-folder.

And I do use simple conditions and rules like this:

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/.+$
RewriteRule ^check-out/?$ index.php?content=check-out [NC,L]

And this works nicely, the way I want to.

So if I'm in location

www.example.com/panel/user

I need something like

RewriteRule ^panel/([^/]+)$ panel/index.php?content=$1 [NC,L]

Where ([^/]+)$ and $1 would in this case represent "user" and site should redirect to

www.example.com/panel/index.php?content=user

Upvotes: 2

Views: 203

Answers (1)

anubhava
anubhava

Reputation: 784908

Inside your panel/.htaccess have this code:

DirectoryIndex index.php
RewriteEngine On

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

Upvotes: 1

Related Questions