Htaccess rewrite url only in one folder - .htaccess

I useing this code in htaccess:
RewriteRule ^([^/]*)/([^/]*)$ /etel.php?q=$1&n=$2 [L]
This control this
domain.com/etel.php?q=501&n=Beef
to this:
domain.com/501/Beef
But if I open the [partner] folder without index.php the htacces open the etel.php. How can I limit that rewrite rule to the parent folder locked out other folder files?

You may use this rule with these 2 RewriteCond to exclude existing files and directories:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /etel.php?q=$1&n=$2 [L,QSA]

Related

.htaccess block all php files with the exepction of some files

Im trying to make a .htaccess file that blocks every folders and file with the exepction of the folder public, the file index.php, the file ajax.php, img, css and js. It should also redirect you to www.domain.com/index.php no matter what you type in the url. Almost everything is working but the ajax.php file is still blocked so my javascript files cant access it. Any suggestions?
My index.php is placed in the folder public, all other php files is placed in a folder named php, js, css and so on but they are not inside public. its like this /root/public and /root/php and so on. The .htaccess file is placed in /root/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php?_url=$1 [QSA,L]
RewriteCond %{REQUEST_URI} !^/(?:public/|index\.php$|ajax\.php$|.+\.(?:jpe?g|gif|png|ico|tiff|css|js)$) [NC]
RewriteRule . - [F]
Have it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(?:public/|(?:index|ajax)\.php$|.+\.(?:jpe?g|gif|png|ico|tiff|css|js)$) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ public/index.php?_url=$1 [QSA,L]

Codeigniter index.php breaking image paths

When I don't edit my .htaccess file, my image path reads something like: http://this.website.com/codeigniter/inc/images/logo.jpg.
However, as soon as I add this code into the .htaccess file:
RewriteEngine On
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?$1 [L]
(to remove the index.php from the URL), I get 404 error, even with the exact same path.
How do I remove index.php and still have access to my images?
RewriteEngine On
RewriteCond $1 !^index\.php [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?$1 [L]
The two new RewriteConditions would exclude existing directories and files (and so images) from redirection.

Make a .htaccess priority over a folder

This is my root folder :
index.php
myfolder (which contains other files, and a htaccess containing "deny from all").
When I access to http://www.domain.com/myfolder, I want to rewrite it to http://www.domain.com/Myfolder, but it seems that it enters in the folder before the RewriteRule (I have a 401).
Here is my .htaccess
# Charset
AddDefaultCharset UTF-8
# URL Rewriting
RewriteEngine on
RewriteCond %{REQUEST_URI} /myfolder
RewriteRule ^(.*)$ /Myfolder [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?nav=$1 [L,QSA]
What's wrong with this ? Thank you !
Well... in fact, there was another .htaccess file in a folder above this folder. Sorry :(

Directory folder not unique in the URL problems (with .html extension removal)

I have my rewrite rules to remove the .html extension. Works fine, apart from one specific .html file, which has the same name as the directory its in. In other words, The directory folder is not unique in the URL, eg test/test.html.
This causes the browser to show the directory structure instead of redirecting to the file.
Anyone know a workaround for this?
My .htaccess file is currently:
RewriteEngine on
RewriteOptions inherit
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Thanks
Dev
Not So Sure Try.
RewriteEngine on
RewriteOptions inherit
RewriteRule /test/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

Htaccess - redirect 'file' from not existing directory

I want to redirect not existing files to index.php in my root directory, and I have this rule in my htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This redirects me http://www.test.de/test.php to index.php properly.
But http://www.test.de/test/test.php does not work. Can I redirect files from not existing diretories?
Thanks for help.
yes, you can.
you can test this one:
RewriteRule ^(.*)$ /index.php [L]

Resources