homepage Welcome to WebmasterWorld Guest from 54.198.135.17
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Need some help with a rewrite rule
mudloop




msg:4404952
 4:03 pm on Jan 8, 2012 (gmt 0)

Hi,

In a product I was involved in that recently shipped, there was an incorrect url. I'd like to solve it with a rewrite rule.

The incorrect url is as follows :
http://domain/connect/connect/etc

So it has /connect in there twice, though it should only be in there once. So I'd need a rewrite rule that removes one of them, but I don't know regex well enough to do it myself (been years since I dabbled with it).

Thanks a lot!

 

gosman




msg:4404964
 5:06 pm on Jan 8, 2012 (gmt 0)

Hi mudloop

rewriterule ^connect/connect/(.*) connect/$1 [L,R=301]

g1smd




msg:4404970
 5:41 pm on Jan 8, 2012 (gmt 0)

The redirect target should also include the protocol and hostname.

This redirect must be placed before any non-www/www redirect code.

Both of these things avoid introducing an unwanted multiple step redirection chain.

gosman




msg:4404985
 6:33 pm on Jan 8, 2012 (gmt 0)

Hi mudloop

rewriterule ^connect/connect/(.*) http://hostname/connect/$1 [L,R=301]

Is what g1smd means.

[edited by: engine at 9:56 am (utc) on Jan 10, 2012]
[edit reason] fixed formatting [/edit]

mudloop




msg:4405448
 3:10 am on Jan 10, 2012 (gmt 0)

Thanks for the reply. It's not functioning as it should though, but I suspect rewrite has been disabled on the server. I've asked the administrator, waiting for his reply.
Curious, what does the [L,R=301] part mean?

lucy24




msg:4405462
 5:05 am on Jan 10, 2012 (gmt 0)

It means you need to do some background reading [httpd.apache.org]. Really.

What happens when you say

RewriteEngine On
RewriteRule ^connect/(connect/.*) http://www.example.com/$1 [L,R=301]

? "Not functioning as it should" implies that it is functioning in some other way. Which is always interesting.

Notice how by capturing the second "connect" I have sneakily saved typing eight characters in the target. It is not necessary to do it this way.

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