Gianmarco Montanari
Gianmarco Montanari

Reputation: 37

How to hide parent folder on URL with htaccess?

I have searched extensively about this problem and haven't been able to find a solution. I'm working locally, so I have this URL:

http://localhost/IASON/iasongitlab/static_website/html/solutions.html

I have managed to hide the file extension, so now my URL are like this:

http://localhost/IASON/iasongitlab/static_website/html/solutions

But now I need to hide the /html/ folder from my URL, so that it looks like this:

http://localhost/IASON/iasongitlab/static_website/solutions

This is just an example. I have multiple views, so I need to code in htaccess to hide the /html/ folder on each view.

This is my htaccess file now:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L] 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

I have tried multiple suggestions without success, and would appreciate any insight into solving this problem.

Upvotes: 2

Views: 341

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133590

With your shown samples, could you please try following. Please make ure you clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteRule ^(IASON/iasongitlab/static_website)/(solutions)/?$ $1/html/$2.html [NC,L]


OR in case you don't want to hardcode the path details and look for solutions at last in uri then you could try following. Make sure you place either following OR above rules only at a time.

RewriteEngine ON
RewriteRule ^(.*)/(solutions)/?$ $1/html/$2.html [NC,L]

Upvotes: 1

Related Questions