homepage Welcome to WebmasterWorld Guest from 54.204.64.152
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Integrating Multiple RewriteCond for QUERY STRINGs
How to integrate multiple RewriteCond rules for redirecting dynamic URLs
pro_seo




msg:4017150
 7:55 pm on Nov 1, 2009 (gmt 0)

Hello,

I have several pages with varying query string values in them.

I am trying to integrate all of those query strings into one rewriterule to redirect all of them to the root.

This is what I have in the htaccess

RewriteCond %{QUERY_STRING} ^ArticleID= [OR]
RewriteCond %{QUERY_STRING} ^DepartmentID= [OR]
RewriteCond %{QUERY_STRING} ^Newsid= [OR]
RewriteCond %{QUERY_STRING} ^NewsID= [OR]
RewriteCond %{QUERY_STRING} ^article=
RewriteRule \.asp$ http://www.example.com/? [R=301, L]

However, this is resulting in a 500 Internal Server error [without the OR directive as well]

Please advise if there's any way to do this or if I need to have separate rules for each of those query strings.

Thanks a lot!

 

jdMorgan




msg:4017165
 8:43 pm on Nov 1, 2009 (gmt 0)

> However, this is resulting in a 500 Internal Server error

Do you have any other working rewriterules?
What is in your server error log when you get the 500 error?

Jim

pro_seo




msg:4017383
 6:29 am on Nov 2, 2009 (gmt 0)

Hi Jim,

I have quite a few other rewriterules as well primarily for security purposes.

#MANY RFI ATTEMPTS USE THE WWW PERL LIBRARY FOR THE SCRIPT AND THIS ATTEMPTS TO BLOCK THEM
RewriteCond %{HTTP_USER_AGENT} libwww-perl [NC]
RewriteRule ^.*$ - [F]

#PREVENT HTTP QUERY STRING
RewriteCond %{QUERY_STRING} ^.*=(htf)tp\://.*$ [NC]
RewriteRule .* - [F,L]

#BLOCK ACCESS TO WP-INCLUDES
RewriteRule ^(wp-includes)\/.*$ ./ [NC,R=301,L]


....and another one for URL rewrite


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Please let me know what other information you need from me to sort this out.

Thanks again as usual :)

jdMorgan




msg:4017614
 5:41 pm on Nov 2, 2009 (gmt 0)

Please address my second question above. Thanks.

Jim

pro_seo




msg:4017623
 6:15 pm on Nov 2, 2009 (gmt 0)

Please address my second question above. Thanks.

This is all I can get Jim


[02/Nov/2009:12:03:21 -0600] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12 GTB5 (.NET CLR 3.5.30729)"

[02/Nov/2009:12:03:21 -0600] "GET /favicon.ico HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12 GTB5 (.NET CLR 3.5.30729)"

[02/Nov/2009:12:03:24 -0600] "GET /favicon.ico HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12 GTB5 (.NET CLR 3.5.30729)"

Hope this helps!

Thanks

jdMorgan




msg:4017718
 7:55 pm on Nov 2, 2009 (gmt 0)

That's a snippet from your access log. What is in your error log? If necessary, ask your host, as proceeding further will be quite difficult without that information.

Jim

pro_seo




msg:4018016
 8:14 am on Nov 3, 2009 (gmt 0)

Hi Jim, I inquired with my host and they said that this was likely caused by an erroneous character in the HTACCESS and such errors are not recorded in the error log.

Is there any other way to sort this out?

Thanks!

jdMorgan




msg:4018160
 1:35 pm on Nov 3, 2009 (gmt 0)

First try examining and then saving your .htaccess file with a very-simple plain-text editor such as Windows NotePad. Re-upload this saved file to the server.

You may or may not see anything wrong when viewing/editing the file, but perhaps the incorrect characters will get re-encoded to something that will show in your error log.

Do be sure in the future to only edit server config files with a plain-text editor.

[added] I just copied and pasted the new rule you posted in your first post above, just in case I might spot an encoded character. I noticed that there is a space between "[R=301," and "L]" in that rule that is not at all obvious when viewed in this forum's font. That space could also be the problem.

Be aware that your are not free to 'format' server config code in any way you like; It should be formatted exactly as specified in the documentation. High-level programming and scripting languages are very forgiving of formatting variations, but Apache modules are not: They are purpose-built and written to be super-efficient and fast; if you make even the smallest mistake, Apache won't forgive it. [/added]

Jim

pro_seo




msg:4018412
 6:50 pm on Nov 3, 2009 (gmt 0)

You're spot on Jim!

That extra character between the ["R=301," and "L]" caused the error.

I have removed that space and the redirects are working fine.

Thanks a ton for your help, as always Jim :)

BTW, is the code I pasted for integrating multiple RewriteCond for Query Strings correct?

Thanks again!

jdMorgan




msg:4018724
 2:27 am on Nov 4, 2009 (gmt 0)

It's correct, but you could use the "local OR" method to shorten it to one RewriteCond line:

RewriteCond %{QUERY_STRING} ^(ArticleID¦DepartmentID¦News(id¦ID)¦article)=

However, you must replace each of the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

pro_seo




msg:4018762
 5:46 am on Nov 4, 2009 (gmt 0)

Ok..thanks a lot Jim :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved