htaccess for subdirectory only - .htaccess

i have a some directory on my www folder
-www (base)
--folder1
--folder2
--folder3
so i want to use some htaccess code for all files and folder (so i just create .htaccess in www folder)
but also i want to add this code just for folder 1,2,3 (and files inside them) and no for other folders or other files in base directory www or other directory
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.m3u8 file.m3u8 [NC,L]
#RewriteCond %{HTTP_USER_AGENT} ^.*(vlc|LibVLC|Android|iPhone).*$ [NC]
# RewriteRule ^(.*)$ http://example.com [L,R=301]

You can add a RewriteCond to restrict your first rule for certain folders only:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(folder1|folder2|folder3)/ [NC]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.m3u8 file.m3u8 [NC,L]
# remaining rules go here

Related

.htaccess Change root directory with exceptions for a list of directories

Hi,
I have my .htaccess code that changes the root directory from public_html to a new-site folder and it's working perfectly.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com.au$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com.au$
RewriteCond %{REQUEST_URI} !new-site/
RewriteRule (.*) /new-site/$1 [L]
the issue with it is: I want to keep a few inner pages from the old site loading from the default directory.
https://example.com.au/load-this-from-the-old-site/
https://example.com.au/load-this-from-the-old-site/another-page/
https://example.com.au/etc/
The above pages are not directories they are pages requested from the old public_html/index.php file
Any help would be appricated
Insert an exclusion condition in your rule like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com\.au$ [NC]
RewriteCond %{REQUEST_URI} !^/(new-site|load-this-from-the-old-site|etc)/ [NC]
RewriteRule (.*) new-site/$1 [L]

Use of .htaccess hides phpmyadmin localhost folder

My problem is when I am using this .htaccess file in my root folder nfs, the folder becomes invisible.
RewriteEngine on
RewriteCond %{THE_REQUEST} !/phpmyadmin [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details1/([0-9]+)/([0-9-]+)$ details1.php?cus_id=$1&ad_id=$2 [NC, L]
Again when I remove the below last line, then nfs folder becomes visible.
RewriteRule ^details1/([0-9]+)/([0-9-]+)$ details1.php?cus_id=$1&ad_id=$2 [NC, L]
I wanted to add url rewrite rule. plz help
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^details1/([0-9]+)/([0-9]+) details1.php?cus_id=$1&ad_id=$2

htaccess removing index.php only root folder

Matured one question which I can not handle himself and is forced to ask for help.
So...
I have configured .htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
This code removes all directories index.php on site. I also need to remove it only in the site root. The problem is that the root can be any subdirectory as "/" and "/some_folder/"
Is it possible to do this without explicit basedir?
For example for CNC I managed to make it so:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . ./ [L]
Thus, the problem:
Site root = httр://site.com/sub/
Remove index.php need only in the root directory.
Rot directory may vary and the decision should be without explicit basedir
You can use this rule to remove index.php from root only:
RewriteCond %{THE_REQUEST} \s/index\.php [NC]
RewriteRule ^index\.php$ / [L,R=301,NC]

mod_rewrite: Redirect sub-domain and folders, but not folder contents

I have assets.domain.com hosting all my images, typefaces, scripts, etc. for a Wordpress installation on the top-level domain. I want to redirect any access to subdomain and folders to top-level domain without affecting the folder contents (lots of file types, so would like to avoid having to list each one as an exemption but if that's my only choice, so be it).
Got close with:
# Enable URL Rewriting
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(images|type|scripts)(/.*|$) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} !images/.* [NC]
RewriteCond %{REQUEST_URI} !type/.* [NC]
RewriteCond %{REQUEST_URI} !scripts/.* [NC]
RewriteRule ^(.*)$ http://www\.domain\.com [L,QSA]
</IfModule>
Thanks to Christopher Brix and mootinator.

.htaccess redirection to folders and subfolders

I am having issues with htaccess redirections. Following is the issues I am having.
The root folder to which the main domain actually points has the following folder: "example"
example.com is actually internally linked to the path "root/example/" rather than "root/". This is done using the following htaccess code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example/index.html [L]
The folder "exmaple" has the following subfolders: newexample, newexample_beta
If I go to the URL "example.com/newexample", the URL needs to be internally linked to "root/example/newexample". But the URL redirects me to "example.com/example/newexample/"
could you please let me know what needs to be done

Resources