ChrisW
ChrisW

Reputation: 5068

.htaccess Rewrite redirecting URLs

In my .htaccess file, I've got the fairly standard

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?p=$1 [NC]

and I only need this to happen to files in my root directory. However, if I go to the URL of one of my subdirectories (with or without a index.php file), such as www.foo.com/bar, then I am redirected to www.foo.com/bar/?p=bar - how do I prevent the addition of ?p=bar?

Upvotes: 0

Views: 126

Answers (2)

Ulrich Palha
Ulrich Palha

Reputation: 9529

You can try making the rule only execute for non directories as below

#if it is not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#then send it to index.php
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?p=$1 [NC,L]

Upvotes: 1

clmarquart
clmarquart

Reputation: 4711

You can put .htaccess files into the sub-directories.

# /bar/.htaccess

AllowOverride none

This should prevent the .htaccess inheritance.

Upvotes: 0

Related Questions