Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess: multiple sub folders and website access

Tags:

.htaccess

I'm being stuck setting up my htaccess properly. Currently I have the following situation and file structure in my htdocs folder:

  • .htaccess
  • /website
  • /clients/blabla
  • /somefolder

As you might guess, the folder "website" contains all the files that should be accessible upon navigation to http://mydomain.com - this works fine with the current htaccess:

RewriteEngine on 

# remove www
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

# subfolder
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/website/
RewriteRule (.*) /website/$1

# clean urls
RewriteRule ^website/([a-z0-9\-]+)$ website/$1.php

My problem: While I want my website to be accessible the way it is now I also want to be able to access http://mydomain.com/clients/blala and http://mydomain.com/somefolder etc... With my current htaccess this results in a 404 Error saying "The requested URL /website/clients/blabla was not found on this server."

What do I need to add / change to my htaccess to make this work?

Thanks in advance

like image 641
maze Avatar asked Mar 18 '26 21:03

maze


1 Answers

This shoud work.

RewriteEngine on 

# remove www
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]

# subfolder
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/website/
RewriteCond %{REQUEST_URI} !^/somefolder/
RewriteCond %{REQUEST_URI} !^/client/blabla/
RewriteRule (.*) /website/$1

# clean urls
RewriteRule ^website/([a-z0-9\-]+)$ website/$1.php
like image 152
benck Avatar answered Mar 24 '26 00:03

benck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!