homepage Welcome to WebmasterWorld Guest from
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 some help with a rewrite rule

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


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 :

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!



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

Hi mudloop

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


 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.


 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]


 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?


 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