Home > Software design >  htaccess rewrite root url to subfolder with accessing other folder?
htaccess rewrite root url to subfolder with accessing other folder?

Time:10-20

I have following folder structure in apache server.

Public_html
-->admin
    --->admin_login.php
-->website
    --->index.php

since the index.php inside the website folder, i have given following code in .htaccess

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

so that the when the user enter root url , it will appear "www.myurl.com" instead of "www.myurl.com/website/"

but the issue is, i could not be able to access admin_login.php.

is there anyway to modify .htaccess, to come website/index.php in main url and able to access admin_login.php(both)?

Thanks in Advance

CodePudding user response:

With your shown samples and attempts please try following .htaccess rules file. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php/?$ website/index.php [QSA,NC,L]

CodePudding user response:

You need to add an exception to existing rule like this:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(website|admin/) [NC]
RewriteRule .* website/$0 [L]

Negative condition %{REQUEST_URI} !^/(website|admin/ will match every URI except URIs that start with /website/ or /admin/. This will allow you to directly open www.myurl.com/admin/admin_login.php.

  • Related