Reputation: 642
example.com/category/fruits">unwanted
example.com/subcategory/apple">&Fweds
I want to remove unwanted symbols which are after fruits* so that it becomes:
example.com/category/fruits
example.com/subcategory/apple
I tried but does not help me :
#removing unwanted symbols from the end
RewriteEngine on
RewriteRule ^(category/(.*)/[\w-]++). /$1 [R=301,L,NC,NE]
RewriteEngine on
RewriteRule ^(subcategory/(.*)/[\w-]++). /$1 [R=301,L,NC,NE]
Upvotes: 2
Views: 191
Reputation: 785481
This single rule should work for both the cases:
RewriteRule ^((?:sub)?category/[\w-]++). /$1 [R=301,L,NC,NE]
Remember there is only one /
after category
or subcategory
before matching fruits
which is matched using possessive quantifier [\w-]++
to disallow backtracking.
Or if category
is just a placeholder:
RewriteRule ^((?:subcategory|category)/[\w-]++). /$1 [R=301,L,NC,NE]
Upvotes: 2
Reputation: 133600
With your shown attempts/rules, please try following. You could combine both the rules shown in your rules file. Please these rules at top of your htaccess file.
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine on
RewriteRule ^(category|subcategory)/([^/]*)/([^&]*)&.* /$1/$2/$3 [R=301,L,NC,NE]
Upvotes: 2