htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Redirect according to specific query string parameter
PostPosted: 12 Mar 2007 14:37 
Offline

Joined: 12 Mar 2007 12:27
Posts: 2
My blog's sitemap was incorrectly showing tag urls of this format:
http://mysite.com/blog/index.php?tag=example

In reality, the tag urls are of this format:
http://mysite.com/index.php?tag=example

I've since corrected the sitemap generator so that its urls are of the correct format, but Google and friends have already indexed some of the bad urls. I'd like to redirect bad url to good url while preserving the query string.

I tried a number of things, and this is what makes the most sense to me, but doesn't work:
RewriteRule ^blog/index\.php\?$ index.php? [R=301,QSA,L]

Any suggestions? Thanks in advance!

Jacob



http://jobmob.co.il/feed/
All Together Now to get jobs and get jobs done.


Top
 Profile  
 
 Post subject: Re: Redirect according to specific query string parameter
PostPosted: 13 Mar 2007 20:46 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
jshare wrote:
My blog's sitemap was incorrectly showing tag urls of this format:
http://mysite.com/blog/index.php?tag=example

In reality, the tag urls are of this format:
http://mysite.com/index.php?tag=example
...
Jacob


Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^blog/index\.php(.*) /index.php%{QUERY_STRING} [R=301,NC,QSA]


Try that and let me know if it works.. basically it checks to make sure that their IS a query string ?tag=example.. and if so it sends a 301 redirect to all requests for /blog/index.php?anything=anything to /index.php?anything=anything.

You could change this to only work for urls that have tag in the query string like this.

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^.*tag.*$
RewriteRule ^blog/index\.php(.*) /index.php%{QUERY_STRING} [R=301,NC,QSA]


Top
 Profile  
 
 Post subject:
PostPosted: 13 Mar 2007 22:34 
Offline

Joined: 12 Mar 2007 12:27
Posts: 2
Produke,
You basically got it.

I needed your tag-specific suggestion but a straight copy&paste gave:

Code:
url: http://mysite.com/blog/index.php?tag=example
Moved Permanently

The document has moved here.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.0.54 Server at mysite.com Port 80


So I added an [L] to the last line:
Code:
RewriteRule ^blog/index\.php(.*) /index.php%{QUERY_STRING} [R=301,NC,QSA,L]


That resulted in the desired redirect but the url was being rewritten incorrectly as:
http://mysite.com/index.phptag=example?tag=example

So there seemed to be a redundant query string call. What worked was:
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^.*tag.*$
RewriteRule ^blog/index\.php(.*) /index.php [R=301,NC,QSA,L]


Thanks alot! I really appreciate it. On topic - what would you say is the best way to design & test rewriterules? Any specific tool recommendations to speed things up?



http://jobmob.co.il/feed/
All Together Now to get jobs and get jobs done.


Top
 Profile  
 
 Post subject:
PostPosted: 13 Mar 2007 22:53 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
jshare wrote:
what would you say is the best way to design & test rewriterules? Any specific tool recommendations to speed things up?


What I do is I have a domain that I use only for testing mod_rewrite..

I don't use any tools.. I i get stumped I post to a forum like this :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: MSNbot Media and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB