Underscores to hyphens, but not after "?"
2 posts
• Page 1 of 1
Underscores to hyphens, but not after "?"
I need to replace underscores “_” with hyphens “-“ in URLs using ISAPI_Rewrite (for SEO reasons). I only need to replace the underscores in the true URL section of the incoming request, not in any parameters which would come after a question mark “?”. For example the request for “http://www.myurl.com/about_us?parameter_with_underscores=123” needs to be rewritten as “http://www.myurl.com/about-us?parameter_with_underscores=123”. My rewrite rule also needs to cover parameter-less requests such as “http://www.myurl.com/about_us” being rewritten to “http://www.myurl.com/about-us”. Every time I make a rule specific enough to not mess with the parameters it ends up not working on the parameter-less variant.
Here’s an example (not good enough) rule I tried:
Rewrite ^(.*)_(.*)(?=.*?\?)(.*) [L,R=301]
Any insights and hints from experienced users would be appreciated.
Here’s an example (not good enough) rule I tried:
Rewrite ^(.*)_(.*)(?=.*?\?)(.*) [L,R=301]
Any insights and hints from experienced users would be appreciated.
- HeliconAndrew
-
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: Underscores to hyphens, but not after "?"
Hello,
The solution would be very simple - QSA-flag. It automatically appends querystring to the landing URL.
Regards
Andrew
The solution would be very simple - QSA-flag. It automatically appends querystring to the landing URL.
- Code: Select all
Rewrite ^([^_]+)_(.*) $1-$2 [NS,QSA,R=301,L]
Regards
Andrew
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 21 guests