homepage Welcome to WebmasterWorld Guest from 54.237.151.188
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Need help stripping a 301 redirect url down
ichthyous

10+ Year Member



 
Msg#: 4285190 posted 5:59 pm on Mar 21, 2011 (gmt 0)

Hi there,

I am trying to 301 redirect a bunch or urls on my gallery site which uses url rewrite. I am not able to rewrite the urls for some reason as the url rewrite code in .htaccess seems to append added url string info at the end of the new url. For instance this rule:

Redirect 301 /photos/washington-dc/rosslyn-virginia-skyline-dusk/ http://example.com/photos/washington-dc/skylines-cityscapes/rosslyn-virginia-skyline-dusk/$

Results in this url:

http://example.com/photos/washington-dc/skylines-cityscapes/rosslyn-virginia-skyline-dusk/$?g2_view=core.ShowItem&g2_path=washington-dc/rosslyn-virginia-skyline-dusk&g2_page=

I need to add something to this rule to strip off this part: $?g2_view=core.ShowItem&g2_path=washington-dc/rosslyn-virginia-skyline-dusk&g2_page=

Hopefully it will redirect properly after that. I appreciate any help!

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4285190 posted 6:08 pm on Mar 21, 2011 (gmt 0)

Yes, Redirect re-appends stuff automatically. However, in this case it looks like you're applying a redirect AFTER the request has already been internally rewritten. This redirect exposes the internal server path back out to the world as a URL.

Use RewriteRule syntax and the [R=301,L] flags.

End the substitution URL with a question mark to clear the query string data in the redirect.

Make sure the new code is positioned before any internal rewrites that will deal with the request.

ichthyous

10+ Year Member



 
Msg#: 4285190 posted 6:52 pm on Mar 21, 2011 (gmt 0)

Ok changed it to this:

RewriteRule ^(photos/)?washington-dc/rosslyn-virginia-skyline-dusk/$ http://example.com/photos/washington-dc/skylines-cityscapes/rosslyn-virginia-skyline-dusk/? [R=301,L]

Didn't work at the top of the list of rewrite rules, before this:

Options +FollowSymlinks
RewriteEngine On

RewriteBase /


But it did work if I placed the rule after the above code and before the rewrite rules for showItem. I would prefer not to stick 200 unqiue rewrite rules in the middle of the main block of gallery rewrite code though because that block is generated automatically by the url rewrite module and if any changes are made to the module it wipes that block and rewrites it all. Can I add the:

Options +FollowSymlinks
RewriteEngine On

RewriteBase /

At the top of the htaccess file? If it's in the htaccess file twice is that a problem? Thanks for the help!

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4285190 posted 6:57 pm on Mar 21, 2011 (gmt 0)

The redirects need to be listed after the point where the module is enabled with the RewriteEngine On directive.

Putting that directive twice can cause problems and is best avoided.

The redirects must be listed before any internal rewrites are found.

The Regeneration code should not be touching the Options, RewriteEngine or RewriteBase directives. Change it not do so.

ichthyous

10+ Year Member



 
Msg#: 4285190 posted 7:30 pm on Mar 21, 2011 (gmt 0)

I moved the rule to directly after RewriteEngine On and before the internal rewrites start. I'm not sure what you mean "the redirects should not be touching..."? There is a line break after so they are not touching...please explain.

I tested this with an http server response code checker and there is a problem. It seems the first time you hit the old url in a browser you get redirected to the site's login page at:

http://example.com/?g2_view=core.UserAdmin&g2_subView=core.UserLogin&g2_return=%2Fphotos%2Fwashington-dc%2Fskylines-cityscapes%2Frosslyn-virginia-skyline-dusk%2F%3Fg2_GALLERYSID%3Da9c5a7024b36fd9318f6ff1c55434e1f&g2_GALLERYSID=a9c5a7024b36fd9318f6ff1c55434e1f&g2_returnName=photo

The server response codes are all correct...show a 301 redirect from 1st url to 2nd, then a 200 OK. But the page shown visually is the login page. It seems that this happens with every browser the 1st time, but if you try again it redirects properly the 2nd time. Looks like session ID problems?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4285190 posted 7:38 pm on Mar 21, 2011 (gmt 0)

You said: "the redirects should not be touching..."?

I actually said: "The Regeneration code should not be touching the Options, RewriteEngine or RewriteBase directives."

That is, your script that wipes the .htaccess file clean and puts new code in it should not be touching the first three directives. It should not wipe those. It should only wipe and rebuild the actual rules.

Make sure you clear your browser cache before every test. You want to make requests to the server, not pull previous responses from the browser cache.

ichthyous

10+ Year Member



 
Msg#: 4285190 posted 8:22 pm on Mar 21, 2011 (gmt 0)

I see ok...something is still not right. After I clear the cache on both IE8 and Firefox I still get redirected to the login page with the url below the first time:

http://example.com/?g2_view=core.UserAdmin&g2_subView=core.UserLogin&g2_return=%2Fphotos%2Fwashington-dc%2Fskylines-cityscapes%2Frosslyn-virginia-skyline-dusk%2F%3Fg2_GALLERYSID%3D66bae00afe3558023b30e2882a665e22&g2_GALLERYSID=66bae00afe3558023b30e2882a665e22&g2_returnName=photo

Then if I clear cache aain I get the correct redirect page. I am using Webmaster tools to clear cache on Firefox and InPrivate browsing+manually clearing the cache on IE8. Very strange...not sure I can trust this if it's going to redirect spiders to the login page.

ichthyous

10+ Year Member



 
Msg#: 4285190 posted 1:38 pm on Mar 22, 2011 (gmt 0)

g1smd...I'm still not able to resolve this. If I clear cache and even use private browsing session I am redirected to the login page each time. If I type it in again I am redirected to the correct page each time. It seems to be a conflict with Session IDs and the redirect. I think if this stays this way I'll have 200 pages indexed as "Welcome please login" etc. Any ideas on how this might be resolved? thanks again

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4285190 posted 8:37 pm on Mar 22, 2011 (gmt 0)

I don't know enough about your site to take a guess.

Hope that jd sees this thread and has a better idea...

ichthyous

10+ Year Member



 
Msg#: 4285190 posted 3:13 pm on Mar 23, 2011 (gmt 0)

I hope so too...I tried stickymail but his box is full. Hopefully he'll see this because I haven't been able to get around the issue and the whole thing is stuck in limbo now

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved