LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-06-2005, 09:02 PM   #1
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
Using mod_rewrite and query_string to remove arguments


Hi y'all!

I just moved one of our corporate sites from an ASP.Net portal (DotNetNuke) to a php solution due to a variety of reasons, one of which is the easy URL Rewriting and the other being performance (DotNetNuke performs HORRIBLY due to its poor design requiring several hundred separate back end queries per page). Because of the way DotNetNuke works, there are multiple URL formats for each request, which while making things flexible, also (presumably) results in duplicate content penalties in various search engines. Oh that's right - I forgot while dealing with the reimplementation that the single biggest reason for dumping DNN was the duplicate content issue!

Anyway, I've worked with mod_rewrite quite a bit where enforcing canonical domains and redirecting requests to a php handler are concerned - but now I want to send a 301 Permanent Redirect response to requests for old pages to force them to drop out of search engines (right now we are returning 404 Page Not Found responses - I'd like to use 410 which is more accurate but I don't know how well googlebot, slurp, msnbot, etc. recognize the "correct" 410 removed header).

The deal is this: we are getting incoming requests from the bots in one of two formats:

First type (DNN default)

[domain]/Default.aspx?tabid=foo

And there may be additional arguments such as:

[domain]/Default.aspx?tabid=foo&argument=bar

second DNN query type

[domain]/foo/Default.aspx

And there may be additional arguments such as:

[domain]/foo/Default.aspx&argument=bar

What I would like to do is set up rules to redirect everything with a 301 header to / so I set up a rule like this:

#RewriteRule ^Default.aspx / [R=301,L]

which does not take the query into account, so a request for, say:

[domain]/Default.aspx?tabid=foo

redirects to:

[domain]/?tabid=foo


My question is this: How do I strip the query out and replace it with nothing? I've read the apache docs on mod_rewrite and all they say is that you can use QUERY_STRING to strip the query and any arguments but there is NO mention of how to use it, nor is there any example. There is plenty of example of passing the queries on to an http handler (which I've done in php sites) but this is a totally different implementation from what I can see.

Does anyone have any pointers to this? Any good documentation or howtos out there?
 
Old 11-07-2005, 08:51 AM   #2
zeitounator
Member
 
Registered: Aug 2003
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262

Rep: Reputation: 30
This should pretty much do what you expect
Code:
RewriteCond %{QUERY_STRING} =""
RewriteRule .*/Default.aspx / [R=permanent,L]

RewriteRule .*/Default.aspx /?%{QUERY_STRING} [R=permanent,L]
 
Old 11-07-2005, 03:18 PM   #3
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Original Poster
Rep: Reputation: 46
Ah, so I was mis-using the query_string directive when I tried it - thanks for the tip, I will try it on Wednesday!
 
Old 11-10-2005, 10:11 PM   #4
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Original Poster
Rep: Reputation: 46
Thanks zeitounator ! It wasn't quite what I wanted but pointed me in exactly the right direction!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mod_rewrite question hct224 Linux - Newbie 5 02-23-2006 11:03 AM
how do i reformat my query_string in PHP? Alexander.s Programming 5 05-02-2005 11:12 AM
Apache Mod_rewrite help! soulsniper Linux - Software 0 01-16-2005 05:23 PM
Apache:mod_rewrite MadMikie Linux - Software 0 08-03-2004 07:33 AM
browser does not convert query_string/url spaces to '+', seeking workaround? Sm0k3 Programming 0 11-25-2003 05:44 PM


All times are GMT -5. The time now is 02:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration