Forum Moderators: phranque

Message Too Old, No Replies

query string at end of redirectmatch 301

         

greennature

11:58 pm on Jan 3, 2006 (gmt 0)



I have a site that had urls with the form..

archives/1_title_of_page.html

I discovered that any combination of words after the page id# would work, i.e.,

archives/1_test.html
archives/1_title-of-page.html

etc., al, making some of the pages duplicates, depending on how they were linked

I decided to change the urls to a straight

article1.html

now I'm trying to redirect all the old urls to the new url

I use
RedirectMatch 301 archives/([0-9]+) [domain.com...]

and it works, except a query string is added to the end of every url

the query string is "?url=/archive"

and I figure it has something to do with a previous rewrite

RewriteRule ^archives([/A-Za-z0-9]+)\.html? index.php?url=/archives/$1.html [L,QSA]

nothing changes even if I remove the "?" after the .html on the original rewrite.

How do you remove the query string after the redirectmatch 301?

BTW...I see the "Go Horns" pic and text at the top and wish to add
"Go Lions" :)

greennature

12:25 am on Jan 4, 2006 (gmt 0)



correction

I think the rewrite command causing the problem is
RewriteRule ^archive/? index.php?url=/archive [L,QSA]

jdMorgan

1:30 am on Jan 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is mainly a directive execuion-order problem. To control the order of directive execution, you'll need to use mod_rewrite for both functions, the external redirect and the internal rewrite to your script. You'll also need to be sure to do the 301 redirect before doing the internal rewrite to the script, otherwise, your script URL will be 'exposed' by the redirect.

Note that the order in which you place directives in your .htaccess file only has meaning if those directives are all processed by the same apache module. You cannot control whether mod_alias directives execute before mod_rewrite directives at this level -- you need httpd.conf priveleges to do that.

It may be clearer if descibed this way: Each Apache module scans your .htaccess file and executes the directives that it recognizes in the order that it finds them. Then the next Apache module scans your file again, and executes the directives that it recognizes. You can control the order of execution only for directives processed by the same module. The order that these modules process your file is determined by the server configuration.

As a result, you've got a fight going on here between mod_alias and mod_rewrite.

Try:


RewriteRule ^archives/([0-9]+) http://example.com/article$1.html [R=301,L]
#
RewriteRule ^archives([/A-Za-z0-9]+)\.htm /index.php?url=/archives/$1.html [QSA,L]

Jim

greennature

6:55 am on Jan 4, 2006 (gmt 0)



That makes perfect sense having to rewrite both and then first redirect the url and then rewrite it.

I think I understand the problem a bit better.

The original url
archives/1_article_name.html

is part of a a few different permalinks possibilities built into the blog that I am using.

Unfortunatley I did not know at the time that the blog doesn't really care what the "article name" is. It serves urls based on the ID only, i.e, the article number and then is uses whatever comes after it as the "proper article_name". In the eyes of the code
archives/1_article_name.html
archives/1_article-name.html
archives/1_article.html AND
archives/1__name.html

are all the same url. That's why there are so many different and duplicate urls show up using that naming scheme.

I tired your suggestion, however it did not work.

the problem is that the url "archives/1_article_name.html" has already been rewritten once

RewriteRule ^(archives/([0-9]+)_[0-9a-z\.\_!;,\+\-]+\.html) index.php?/$1 [L,QSA]

Because it is written into the code, it works whether you use the rewrite or not. I do NOT have that rewrite in my .htaccess, and the urls still work.

So, it's back to the drawing board.

BTW...WTG LIONS :)