![]() |
|
|
#1
|
|||
|
|||
|
mod_rewrite and redirects
Hi,
I've got an old site which I'm in the process of sorting the internal linking out on. The old url looked like index.php?topic=xxxx The new url looks like topic/xxxx So I put a rewriterule in for this: RewriteRule topic/(.*)$ /index.php?topic=$1 [L] This works fine, but the old urls are in various links and cached on the SEs, so I want to redirect the old to the new. I thought the following would do the trick: RewriteRule topic/(.*)$ /index.php?topic=$1 [L] RedirectMatch 301 index.php?topic=$1 http://domainname/topic/$1 However, the 301 seems to be doing nothing. I don't know if what I'm trying to do is even possible without causing a loop of somekind. Anyone any views/ideas ?? I've also tried RewriteRule index.php?topic=(.*)$ /topic/$1 [R=301, L] but that gave bad flag deliminator errors. J |
|
#2
|
|||
|
|||
|
getting rid of the space in the [R=301, L] so it reads [R=301,L] got rid of the flag error - but it still seems to do nothing.
|
|
#3
|
|||
|
|||
|
Quote:
Quote:
index.phptopic=... index.phtopic=... Escape question mark (as well as other characters - periods, parenthesis, etc) with a slash: index.php\?topic=(.*)$ J.D. |
|
#4
|
|||
|
|||
|
Quote:
Quote:
![]() Quote:
|
|
#5
|
|||
|
|||
|
Quote:
J.D. |
|
#6
|
|||
|
|||
|
lets just make sure I'm being clear on what I want to do.
I want to do a 301 redirect on a url like /index.php?topic=xxxx to /topic/xxxx where xxx could be any number of things. I would have thought that the only things that need escaping are the ? and perhaps the = anyways, to try and avoid any escaping problems, I thought perhaps RewiteRule index.php(.)topic(.)(.*)$ /topic/$3 but that also has no effect. I'm working on a .htaccess in the root folder (there are no other folders). |
|
#7
|
|||
|
|||
|
fk'it this is giving me a headache.
I'll just write off current IBL's, wait for the site to be spidered again and then start a new link campaign. There's only about 40 IBL's that I know of, so it's only a day or so's work to replace them. |
|
#8
|
||||
|
||||
|
Try including a ? at the end of the rewritten string - it seems like I remember this same issue with a client a while back - the rewrite would keep failing when it seemed it should work - I guess it was still looking for the variable but adding the ? with no data after it turned out the proper result for us
I'll try to dig up that actual string if I can find it |
|
#9
|
|||
|
|||
|
Quote:
RewriteCond %{QUERY_STRING} ^topic=(.*)$ RewriteRule ^index\.php$ /topic/%1? [R=301,L] J.D. |
|
#10
|
|||
|
|||
|
yep, that did it.
Let me see if I understand what your rewrite will do: if QUERY_STRING begins with topic= take everything after the topic assign it to variable and apply the rule. rewrite rule says if url starts with index.php rewrite it to /topic/variable redirected with a 301 That worked and produced the 301. Now what I hoped wouldn't happen does it loops because of the static rewrite to the dynamic
|
|
#11
|
|||
|
|||
|
sorted
![]() I've now got this RewriteCond %{QUERY_STRING} ^topic=(.*)$ RewriteRule ^index.php$ /topic/%1? [R=301,L] RewriteRule topic/(.*)$ /index.php?jon=1&topic=$1 [L] Note the extra jon=1& in the final rewrite (this isn't used in any script) but it stops the rules looping ![]() Yipee, no need to disregard those links. |
|
#12
|
|||
|
|||
|
thanks!
I have been pulling my hair out on this exact same problem for about 4 hours. I dont normally reply on threads but this was a real Eureka moment so thanks very much!
regular expressions is a bit of a nightmare when your just starting! |
![]() |
| Bookmarks |
| Thread Tools | |
|
|