I have this .htaccess file as generated by WordPress and an eCommerce plugin:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^.products/images/(d+)/???(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I now have to redirect someone who visits http://mydomain.com/golf to http://mydomain.com/products/category/golf/
I have these rules in a block above the existing block which semi-work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^golf.*$ products/category/golf/ [R=permanent,L]
RewriteRule ^cycling.*$ products/category/cycling/ [R=permanent,L]
#...etc
</IfModule>
The problem is, if someone types http://mydomain.com/golfshoes for example, it still redirects. I have tried to play about with the wildcards etc but cant get it to only allow /golf and /golf/
Also… is that the most efficient way of setting these rules up? I should I be doing some sort of if or if or if then redirect?
Thanks 🙂
Ben
Try changing the 2 regular expressions to:
The (/.*) matches a “/” or “/something”, and the ? means that it may not be there. The $1 at the target indicates whatever was matched in the parentheses. So someone going to http://mydomain.com/golf/foo.html will get served
/prodducts/category/golf/foo.html