Welcome to WebmasterWorld Guest from 54.162.94.15

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Integrating Multiple RewriteCond for QUERY STRINGs

How to integrate multiple RewriteCond rules for redirecting dynamic URLs

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

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts:97
votes: 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!

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 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

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

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts:97
votes: 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} ^.*=(htŠf)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 :)

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Please address my second question above. Thanks.

Jim

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

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts:97
votes: 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

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 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

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

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts:97
votes: 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!

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 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

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

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts:97
votes: 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!

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 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

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

Junior Member

10+ Year Member

joined:Jan 11, 2007
posts:97
votes: 0


Ok..thanks a lot Jim :)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members