Reputation: 4079
I've tried all suggestions here and else where but I can't hide the redirect from a .htacess
rewrite rule. My full .htaccess is:
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^classes/(.+)?$ index.php [L]
#shop
RewriteRule ^shop/(sector1|sector2|sector3|sector4)/([A-Za-z0-9-]+) shop?site=$1&category=$2 [NC]
RewriteRule ^shop/(sector1|sector2|sector3|sector4)/$ shop?site=$1 [NC,L]
Mose of the advice I've gotten is to remove [r=301]
but I've never had that flag there. No matter what I try example.com/shop/sector1
always displays as example.com/shop?site=sector1
any help appreciated
[edit] I'm running this on localhost as a virtual host. Mac OS 7.5, Apache 2.2.26
[edit] Also from the doc root there are other .htaccess
files, but none in the 'shop' folder with the above rewrite is supposed to effect.
$ find . -name .htaccess
./.htaccess
./assets/images/.htaccess
./cms/.htaccess
./cms/assets/images/.htaccess
./cms/assets/plugins/ckfinder/userfiles/.htaccess
./cms/modules/default_images/.htaccess
./sagepay/VspPHPKit/demo/.htaccess
./sagepay/VspPHPKit/lib/.htaccess
./uploads/.htaccess
./uploads/products/.htaccess
Also my directory structure is (notice that my redirect shop
is an actual folder - could this be part of the issue?):
$ tree -d -L 1 ./
./
├── assets
├── classes
├── cms
├── contact
├── foo
├── news
├── page
├── products
├── sagepay
├── sample
├── search
├── services
├── shop
├── snippets
├── uploads
└── widgets
Upvotes: 1
Views: 80
Reputation: 785406
Missing trailing slash in your rewritten URI after shop
is the problem since it is a real directory and Apache's mod_dir
will do a 301 redirect to add trailing slash to make /shop/
and that will make final URL as: example.com/shop/?site=sector1
Also better to change order of your rules and make sure to use L
flag at the end of each rule:
RewriteEngine On
RewriteBase /
RewriteRule ^shop/(sector1|sector2|sector3|sector4)/([A-Za-z0-9-]+) shop/?site=$1&category=$2 [L,QSA,NC]
RewriteRule ^shop/(sector1|sector2|sector3|sector4)/$ shop/?site=$1 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^classes/ index.php [L,NC]
Also I suggest you to test your rule in a separate browser.
Upvotes: 1
Reputation: 6004
This might sound really dumb but it caught me out many moons ago. Given that your code looks fine to me it leads me wonder...
When I found this happening myself, it turned out that all my href
attributes were actually the after-redirect address! E.g. double check that your href
attributes are example.com/shop/sector1
and not example.com/shop?site=sector1
.
Otherwise something else might be interfering. Do you have any other code in your htaccess? Any PHP redirecting etc?
Upvotes: 0