RewriteCond and RewriteRule exclude specific folder - .htaccess

I am using the following .htacces file in my domain root.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|admin|cache)
RewriteRule ^(.*)$ index.php [L]
One problem, is when I try to open the file located at cache/themes/theme1/global.css
But for some reasons it doesn't exclude the folder cache from the RewriteRule
Anyone know a solution for this?

I didn't test this but should work;
RewriteEngine on
RewriteRule ^(cache.*)$ $1 [L]
RewriteCond $1 !^(index\.php|images|robots\.txt|admin|cache)
RewriteRule ^(.*)$ index.php [L]

Related

Local debugging codeigniter with dbg-wizard.php

I removed index.php using this .htaccess file:
RewriteEngine on
RewriteBase /job
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads)
RewriteRule ^(.*)$ index.php/$1 [L]
Now Cannot debug with PhpEd. PhpEd need to acces dbg-wizard.php file in the root folder but it's not accessible anymore!
Change your code to this:
RewriteEngine on
RewriteBase /job/
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads|dbg-wizard\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
Have added dbg-wizard.php to the list of things to skip.

.htaccess exception for one folder

I have this one .htaccess:
RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^(.*) $1 [L]
RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
Now I want to upload separate scripts to the beta/ folder, what I must change in .htaccess for right working script in beta/ folder separately?
You can use:
RewriteEngine on
RewriteCond %{request_filename} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !^/beta/ [NC]
RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L]
The simplest approach would be to create another .htaccess and put it your beta/ folder. It'd then can override what's "parent" .htaccess set.

htaccess file misconfigured

I am using codeigniter php framework. I am trying to access a folder under public_html, but I can't get to it. It shows 404 custom page by codeigniter. Does the following script in .htaccess has something to do with it?
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Thanks
It probably is, you can try adding either some conditions:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Or include your folder as part of the exclusion (example, your folder is "foobar"):
RewriteEngine on
RewriteCond $1 !^(index\.php|js|images|robots\.txt|foobar)
RewriteRule ^(.*)$ /index.php/$1 [L]

.htaccess RewriteRule if exists in subdirectory

I had some experience with .htaccess and the mod_rewrite but I can't get this to work. Basically I wan't all URLs redirected to index.php EXCEPT those who point an existing files in the "public" subdirectory.
For example, if I have a file like /public/logo.png I want this:
http://example.com/logo.png -> /public/logo.png
http://example.com/logo2.png -> index.php (logo2.png does not exist)
http://example.com/whatever -> index.php
Thank you :)
Thanks to Amine help I finally solved this, even though this looks quite messy:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ - [L]
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule ^(.*)$ /public/$1 [L]
RewriteRule ^(.*)$ /index.php [L]
Hope it helps
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule ^(.*)$ /public/$1 [L]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.*)$ /index.php [R=301,L]

WordPress - MultiSite: Are you sure you want to do this? Please try again

I have problem on my blog: http://osify.com while processing add new post with above error message. I tried to disable all plugins or changed theme, the error is still the same.
I found the issue might link to the media upload, it is not be able to post any image, it's waiting at: "Crunching…" with no continue but the file was in the folder (checked via FTP)
And I already tried to chmod the folder to 777 (before it's 755 for folder, 644 for files)
I think it might link to multi-site issue on shared hosting but no clear idea or clue about that.
My .htaccess
#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
[..]
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
It seems just happen when I enable my sub site
Is there any way to solve this issue?
Thanks for advise,
The amount your .htaccess is ganked....
REMOVE this part up at the top.
#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]
The ONLY WP calls you should have in there should match this: http://codex.wordpress.org/Multisite_Network_Administration#.htaccess_and_Mod_Rewrite
Re-uplaod your Wp-admin files
this will solve your problem

Resources