.htaccess rules to ignore the main directory .htaccess file if specific subfolder is requested in URI - .htaccess

I have three subfolders /software1/, /software2/ and /software3/ for three different applications in the main root directory for domain.com. The .htaccess rules for these subfolders are interfering with the .htaccess file in the main directory. So, I wonder if there is a rule to add into the .htaccess file in the main directory to ignore the rest of the file and directly jump into the /software1/, /software2/ and /software3/ subfolders (i.e. their .htaccess files) if URI is http://domain.com/software1/..., http://domain.com/software2/... and http://domain.com/software3/...?

It would have been nice to see your current .htaccess rules so we can see what it's doing or not doing. But if you just want to not do anything for the 3 directories, you can try this in the main .htaccess and just have it not do anything if it is one of those 3 directories.
RewriteEngine On
RewriteRule ^(software1|software2|software3)$ - [L,NC]

Related

Rewrite rule to redirect to file and not folder with same name

I am working on a new website and I want the following url /newsite/products to redirect to /newsite/products/product.php.
My .htaccess file is as follows:
RewriteEngine On
RewriteRule ^newsite/products$ /newsite/products/product.php
My problem is that there is already a folder called products within newsite and when requesting newsite/products it tries to open that folder rather than go to the php file.
I get:
Forbidden
You don't have permission to access /newsite/products/ on this server.
Is there any way to make this work?
EDIT: Requested url is: http://example.com/newsite/products and location of .htaccess is in root.
You need to turn off the directory slash to rewrite your file :
Try :
DirectorySlash off
RewriteEngine On
RewriteRule ^newsite/products$ /newsite/products/product.php [NC,L]
Don't add a trailing slash in rule pattern
/newsite/products
will rewrite to
/newsite/products/product.php
and
/newsite/products/
will open your "products" directory
Note- this is not a safe solution, if you remove the rule and DirectorySlash is off, Your index file will be ignored ,all directories will start listing files and folders.

mod_rewrite: rewriting existing directory with htaccess in it

how can I tell mod_rewrite that ALL existing directories should be rewritten?
I have an subdirectory with a .htaccess-File which rewrites too. When I go to domian.tld/sub_with_htaccess, Apache only reads the htaccess in "sub_with_htaccess" but do not read the .htaccess in / which is more important for me.
BUT: When I have a subdomain (sub.domain.tld) whose document root points on /var/www/domain-tld/sub_with_htaccess, I want that only the .htaccess in "sub_with_htaccess" decides what to do.
Any ideas? :)
You can try adding the RewriteOption directive in the htaccess file in the sub_with_htaccess directory:
RewriteOption Inherit
This will make it so rules from parent directories get appended after the rules in this htaccess file. If you are using apache 2.4, you can also use the InheritBefore option which will place the parent htaccess' mod_rewrite rules before the rules in this htaccess file.

load up an htaccess file thats in another directory not in the DocumentRoot

Is it possible to apply htaccess rules that are located in another directory.
for example
/folder
--|__ .htaccess
--|__ /htdocs
--------|__ index.php
the DocumentRoot is htdocs, while the htaccess file is located outside of that.
Can I access that htaccess file?
Edit: .htaccess rules apply to subdirectories too, so yes, you can place the file one level above htdocs. The rules in it will apply.

simple .htaccess rewrite URL to different directory on same server

Ok, I'm clueless here...
I need to rewrite a directory structure and all sub-directories within it to a directory within the same server, but a root that is before the directory.
For example:
http://www.mydomain.com/Themes/default/css/folder
and all directories called upon after folder. Such as folder/sub_folder or folder/afolder/anotherfolder, it needs to include ALL sub-directories within the folder directory.
should be redirected to this:
http://www.mydomain.com
How do I do this via a .htaccess file within the folder path http://www.mydomain.com/Themes/default/css/folder?
Please someone help.
Thanks guys :)
The files within the directory structure still need to be accessible for that structure when called via PHP, but I don't want people being able to browse to http://www.mydomain.com/Themes/default/css/folder and be shown all subdirectories within that folderpath and/or all files. Same thing for all sub-directories that follow that folder path.
I'd like to be able to place the .htaccess file within the http://www.mydomain.com/Themes/default/css/folder directory on the server, but don't know exactly what code to use for this.
ALSO, even more challenging... The domain name can change, so I'd rather not use the domain name within the .htaccess file, instead perhaps use .. or . to go up a directory or a different method of grabbing the domain name within the .htaccess file.
Create a .htaccess file in /Themes/default/css/folder and place these lines there (it requires mod_rewrite):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ http://%{HTTP_HOST}/ [R=301,L]
It will redirect (301 Permanent Redirect) all requests to a folder to a homepage. If file is requested, it will allow it.
If you want to have it working for folders as well as files then remove the RewriteCond line -- it will redirect ALL requests (even for non-existing URLs) to a homepage.
If you will see "500 Internal Server Error" after creating such file, then it is your server configuration: mod_rewrite may not be enabled or it's directives (RewriteRule, RewriteCond, RewriteEngine) are not allowed to be placed in .htaccess. In any case -- check Apache's error log for exact error message (it will give you the exact reason).
http://www.besthostratings.com/articles/prevent-directory-listing.html
IndexIgnore *

Multiple htaccess files with different rewrite rules

I have 2 .htaccess files - one in root directory, another in subdirectory:
accordingly docroot/ and /subdirectory/docroot (this one works like a separate account).
The problem is that there are different rewrite rules in both files. Basicly, the problem is that the .htaccess in subdirectory doesn't work and/or is ignored.
What I am trying to achieve is to have one set of rewrite rules for docroot and other set of rewrite rules for subdirectory/docroot
edit:
the .htaccess file in subdirectory/docroot basicly strips index.php from url, and it actually works, but when i go to subdirectory/user it redirects to subdirectory/user/login (instead of subdirectory/index.php/user/login -- this parts is ok) but the website shows the root page (not subdirectory, but domain root)
Any ideas?
I just had to set RewriteBase to that particular subdirectory to make things work.

Resources