Forum Moderators: phranque

Message Too Old, No Replies

Redirecting folders using 301

Having problems making this work

         

fastnoc

5:07 pm on Aug 23, 2007 (gmt 0)

10+ Year Member



I've tried three ways to make this work and I'm not getting much success.

Here's the scenario.

I have a website. I just changed the theme. The theme is called in the URL.

I've got tons of referrers that come in from other sites, so I need to redirect the url to my new thems. Here's the issue:

All pages coming to this http://www.example.com/index.php?/sg_distro/comments/

Need to change this:

http://www.example.com/index.php?/en/story-details/$1

I'm assuming the $1 will allow any additional string to follow.

The articles use a directory name instead of a real file. Here is a typical link to a story:

http://www.example.com/index.php?/sg_distro/comments/hillary_flipflops/

This needs to change to this:

http://www.example.com/index.php?/en/story-details/hillary_flipflops/

of course the 'hillary_flipflops' needs to be a variable.

I've searched and the results I see just don't seem to work on this particular issue.

Any help is appreciated

[edited by: jdMorgan at 5:38 pm (utc) on Aug. 23, 2007]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

5:40 pm on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi fastnoc,

I've tried three ways to make this work and I'm not getting much success.

Please post your best or most recent effort as a basis for discussion. We need to know where you're starting from, so we can get you going more quickly.

Jim

fastnoc

5:54 pm on Aug 23, 2007 (gmt 0)

10+ Year Member



Hello. No problem. Here was my first try:

Redirect /index.php?/sg_distro http://www.example.com/index.php?/en/story-details/
Redirect /index.php?/sg_distro/comments http://www.example.com/index.php?/en/story-details/

I also tried this to no avail

RewriteCond %{HTTP_HOST} ^example.com/index.php?/sg_distro/comments/ [NC]
RewriteRule ^(.*)$ http://www.example.com/index.php?/en/story-details/$1 [L,R=301]

[edited by: jdMorgan at 11:05 pm (utc) on Aug. 23, 2007]
[edit reason] Example.com [/edit]

fastnoc

5:54 pm on Aug 23, 2007 (gmt 0)

10+ Year Member



I couldn't figure out how to stop the forum from parsing my URL. if it's still abusing the TOS i'm sorry.

g1smd

7:53 pm on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I put the URLs in italics and that stops it:

http://www.example.com/

jdMorgan

11:21 pm on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're trying to match URL-paths with hostnames, and query strings are not visible to RewriteRule, so...

To redirect http://www.example.com/index.php?/sg_distro/comments/<something>/ to
http://www.example.com/index.php?/en/story-details/<something>/
try:


RewriteCond %{QUERY_STRING} ^/sg_distro/comments/([^/]+)/$
RewriteRule ^index\.php$ http://www.example.com/index.php?/en/story-details/%1 [R=301,L]

example.com won't auto-link. If you wish to prevent auto-linking on another 'approved' example domain, such as quux-foo.com, simply place any bbCode pair such as [ b ][ /b ] or [ i ][ /i ] after the "http:". You can also use the single tag [ smilestopper ] in the same way. (Spaces added so markup is visible)

Jim

fastnoc

2:20 am on Aug 24, 2007 (gmt 0)

10+ Year Member



Wow, thank you! That's perfect.

This is really a great forum. Since I found it searching today I see a ton of great things here. Definitely bookmarked!