Posts

Showing posts with the label mod-rewrite

htaccess redirect url with special characters (+)

Image
Clash Royale CLAN TAG #URR8PPP htaccess redirect url with special characters (+) I have a URL like this. http://olddomain.com/product-category/x-tended+bottoms/ and I wanted to apply a 301 redirect via htaccess to http://newdomain.com/shop/extended-bottoms However, when i'm trying to apply a rule that goes like this, it doesn't take effect and instead lands me to page not found. RedirectMatch 301 ^/product-category/x-tended+bottoms/(.*)$ https://mothersenvogue.com.hk/shop/all-bottoms? RedirectMatch 301 ^/product-category/x-tended+bottoms/(.*)$ https://mothersenvogue.com.hk/shop/all-bottoms? What regex can I use to change the plus sign (+) on the url? 1 Answer 1 So I was able to find a reference answer to my question by adding the highlighted rule to check the plus sign (+) on URLs: RedirectMatch 301 ^/product-category/x-tended**[s+]**bottoms/$ https://newdomain.com/?$ htaccess redirect a plu...

htaccess redirect and rewrite rules conflicting

Image
Clash Royale CLAN TAG #URR8PPP htaccess redirect and rewrite rules conflicting I want to rewrite all requests to index.php?r= So that /sth becomes /index.php?r=sth I have applied this rule that works: RewriteCond %{REQUEST_URI} !^/index.php$ RewriteCond %{REQUEST_URI} !^.*.(jpg|css|js|gif|png|pdf|php)$ [NC] RewriteRule ^(.+)$ index.php?r=$1 [L] However I want to also have redirects such as Redirect 301 /sth /sth-new What happens is that it works but the url becomes: /sth-new?r=sth Do you have any solutions - suggestions about why this is happening? How can I implement a global rule and also have simple redirects? 1 Answer 1 You can do it like this: RewriteRule ^sth/?$ /sth-new? [L,R=301] RewriteCond %{REQUEST_URI} !^/index.php$ RewriteCond %{REQUEST_URI} !.(jpg|css|js|gif|png|pdf|php)$ [NC] RewriteRule ^(.+)$ index.php?r=$1 [L] You should keep external redirect rules before your internal rewrite rul...