Forum Moderators: phranque

Message Too Old, No Replies

Rewriting a blank query string

         

oswald_yang

12:10 pm on Nov 16, 2010 (gmt 0)

10+ Year Member



Hi,

I've been doing a bunch of rewrites for a client. There is one that I'm struggling with though.

I need:

http://www.sitename.com/pls/cms/skill_portal.provider_output_full


To 301 to:

http://www.sitename.com/train/training_providers/


I've tried:

RewriteRule ^/pls/cms/skill_portal\.provider_output_full$ http://www.sitename.com/train/training_providers/ [R=301,L]


and:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/pls/cms/skill_portal\.provider_output$ http://www.sitename.com/train/training_providers/ [R=301,L]


The last rule is the one I need to work, is there a way to specify a blank query string? Basically I just need the rule to match input then redirect, but it's not. Any advice welcome.

Thanks,
Charl

jdMorgan

1:57 pm on Nov 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is correct if it is located in one of your server config files, such as httpd.conf.

If it is located in example.com/.htaccess, and if /pls is a subdirectory of example.com/ then remove the leading slash from the RewriteRule pattern.

Both the location of the code and the pattern must be correct for this to work. Your RewriteCond is correct as-is, although using RewriteCond %{QUERY_STRING} ="" would be very slightly faster, since an exact string compare is slightly simpler/faster than a regular-expressions pattern-match.

Jim

oswald_yang

8:49 am on Nov 17, 2010 (gmt 0)

10+ Year Member



Hey Jim,

The code is in a vhost file. So I tried it again and still no luck, then started seeking the problem elsewhere and sigh...

See my original post, the first rule has (which is correct):

.provider_output_full$


and the second:

.provider_output$


So I was being negligent, I did learn though that "" is slightly faster than ^$

As always thanks for the informative, swift reply :)

Cheers,
Charl

jdMorgan

10:53 pm on Nov 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It may (or may not) relieve you to know that even after long experience with exquisitely-complicated mod_rewrite rules, it is *still* very easy to trip over a typo... :)

Jim