How to ignore .htaccess file from a parent directory? - .htaccess

I'm using rewrite rules for nice URL's on my websites, the problem is, that I'm supposed to upload a new website and keep an already existing e-shop running. The e-shop is in it's own folder called "shop" in the "/www" directory on the server.
But now my .htaccess file is messing with the e-shop, although it's in the parent directory, how should I block it's effects in the "/shop" dir?
Here's the code:
RewriteRule ^shop/?$ shop/ [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3&detail4=$4 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?detail1=$1 [QSA,L]
Thanks for any help, Mike.

Try adding this above all of your rules:
RewriteCond %{REQUEST_URI} !^/shop
Then add a .htaccess file to the /shop directory with just this in it.
RewriteOptions Inherit

Related

modify .htaccess rewrite rule

I am new to web development. In my site I have public_html folder and it has the app folder. I have following RewriteRule in my htaccess file :
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
Now I want to modify the rule such a way that if I create new folder profile under public_html than it should display the index.php of the profile folder. Basically, If I type www.example.com/profile in browser window, it should display the content of index.php file.
There are a few ways you could do this, but this should be the simplest way for you.
RewriteRule ^[a-z0-9_-]+/?$ ./profile/index.php [L,NC]

How can I change my .htaccess file in cakephp

I have URL like :
localhost/admin/app/webroot
For this the css in default.ctp taken /app/webroot/css/style.css path.
so my css is not loading.
Should I have to change .htaccess file for this ?
There are 3 .htaccess file in project.
1) which is located in admin/.htaccess
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
2) which is located in admin/app/.htaccess
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
3) which is located in admin/app/webroot/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
please help to resolve my problem.
Thanks in advance.
The simplest way of dealing with this is to set your application up in "Production Mode" as described here
Essentially it means you point your document root to the /app/webroot directory of your Cake App, this makes everything really simple and means you can use the default .htaccess files to handle the rewriting.
If you are trying to put this into a subdirectory you might need to set the base for Rewrite to work on:
RewriteBase /admin
This also assumes you have mod_rewrite enabled on your server!
I found the answer :
If we can add
Configure::write('App.base', '/admin/');
in bootstrap.php file then it works for me.
Thanks for your help.

Problems with htaccess, rewriting to files in directory

I'm having trouble rewriting a series of files in my directory with RewriteRules in .htaccess.
I have index.php?page=page_name
This one is working so far, and I've been successful with it.
#RewriteRule ^([A-Za-a0-9-]+)/?$ index.php?page=$1 [NC]
#RewriteRule ^([A-Za-a0-9-]+)/([0-9-]+)/([A-Za-a0-9-]+)?$ index.php?page=$1&id=$2&name=$3 [NC]
I've been able to do this for views, linked through the index.php file, which is the above named ones.
My challenge is linking files in public_html/view/css/style.css directory to make it look like public_html/css/style.css
This is what I've been trying so far, which isn't working:
#RewriteRule ^css/(.*)$ /view/css/$1 [NC,L]
I have files in:
view/css
view/js
and some other directory. I want them to look like:
domain_name.com/css/style.css
domain_name.com/js/style.css
Please tell me what am I doing wrong and why this is not working.
You can use this rule in your root .htaccess:
RewriteRule ^(js|css)/(.+)$ /view/$1/$2 [NC,L]
Remove the # sign; it turns the entire line into a comment and means your rule is never executed:
RewriteRule ^css/(.*)$ /view/css/$1 [NC,L]
RewriteRule ^js/(.*)$ /view/js/$1 [NC,L]

Hiding index.php from ALL subdirectories using .htaccess

So I'm building an ecommerce website using a file structure suggested to me, it looks like this:
http://www.sample.com/index.php
http://www.sample.com/department/index.php
http://www.sample.com/department/men/index.php
Basically I want to get rid of all the index.php filenames in the url, so it looks like this:
http://www.sample.com
http://www.sample.com/department
http://www.sample.com/department/men
I've achieved this for my homepage with adding this code in .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
But, is there any way to apply this rule to every subdirectory in my site with just editing the root .htaccess file? I'm guessing it can be done by adding this rule in .htaccess files in every directory but I'd rather just have one.
Also, is this even a good way to structure a website? I am not particularly fond of it as there are so many index.php files but I'm not sure of a better alternative...
Try putting these rules above the rules that you have in your htaccess file in the document root:
RewriteRule ^index.php$ / [L,R=301]
RewriteRule ^(.+)/index.php$ /$1/ [L,R=301]

Codeigniter within directory htaccess

I have a codeigniter project light inside the folder projects, it looks like this site.com/projects/light. For some reason the standard .htaccess will not route all calls to index.php. What needs to be changed or added?
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
It looks like the RewriteRule is redirecting to /index.php, rather than /projects/light/index.php.

Resources