You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Josh Trutwin <jo...@trutwins.homeip.net> on 2007/02/22 19:20:51 UTC

[users@httpd] avoiding a redirect loop with rewrites

Hi,

I'm working for a small company that uses a custom CMS.  When
customers create pages in the CMS a file gets created based on the
page's id number - for example:

www.mysite.com/pages/pid5.html

I've pushed some code into the CMS that lets the site admin create a
nice URL for each page so you get something nicer like:

www.mysite.com/products.html

The pid5.html file still exists but now they should see the new URL
everywhere on the site.  The rule I used for this was:

RewriteRule ^products.html$ /pages/pid5.html [L,QSA,NC]

One of the folks in charge here wanted to make sure that for
existing sites anyone who still had the old URL bookmarked or search
engines that have the old URL gets a permanent redirect to the new
one to avoid having two URLs that go to the same place.  I thought
I'd do this with a RedirectPermanent, but when I do that I get a
redirect loop.  I also tried creating rewrite rules for the pid5.html
page - no luck.

Basically, is there any way to have a rewrite rule map a new URL name
to an existing page, and also a permanent redirect for anyone using
the old URL name.  I would have to think this has come up before but
wasn't able to find anything.

Thanks for your help,

Josh

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] avoiding a redirect loop with rewrites

Posted by matt farey <ma...@gmail.com>.

Josh Trutwin wrote:
> On Thu, 22 Feb 2007 21:36:03 +0000
> matt farey <ma...@gmail.com> wrote:
>
>   
>> RewriteEngine On
>> ReWriteCond %{REQUEST_FILENAME} pid5.html$
>> ReWriteCond %{QUERY_STRING} !stop=yes
>> ReWriteRule . /products.html [R=301]
>> ReWriteRule ^products.html$ /pages/pid5.html?stop=yes [L,QSA]
>>     
>
> Thanks Matt - I'll give that a try to see if it fits the works.  I
> assume this would still work too if I wanted to be as specific as
> possible:
>
> ReWriteCond %{REQUEST_FILENAME} pages/pid5.html$
>
>   
>> I'll be embarrassed if it works, the easier way would be to let
>> your CMS handle this internally using PHP perhaps, then the rewrite
>> rules can be simple,a dnt eh CMS ensures the right url in all the
>> links.
>>     
>
> The CMS is written in PhP and I am trying to catch all instances of
> the old URL where I can and replacing with the new URL (the rules are
> also stored in a db for quick lookup).  So *internally* all the
> pidXX.html references should be taken care of.
>
>   
>> Where does the bookmark come from, chase down all the places where
>> they can see that link, and force it to be the new url, all seems a
>> bit backward. Next time tell your boss, "look you employed me to do
>> this job, so trust me to do it" sounds like a micro manager!
>>     
>
> Well - technically not a manager - a reseller I think.  Here's
> verbatim what they told me (old pages = pages/pidXX.html):
>
> "If we are changing url paths, we will need to setup 301's in
> their .htaccess files from the old pages to the 'new' pages. Thats
> the only way to insure the rankings wont drop.  ...  You want to
> avoid systems that create two separate instances of a page that have
> identical content but are addressable from different URLs. Duplicate
> content risks the appearance of "spamming" the search index."
>
> The big concern I think is Search Engines finding two URLs to the
> same page and somehow punishing the site because of it.  They might
> have pages/pid5.html as the products page and then crawl the site to
> find the link products.html is the same page.  
>
> I don't know enough about SEO to say much about this.
>   
yes you can make it as specific as you like
well the only way SE would find 2 urls is if the 2 urls are on your site
and being indexed by the bots, OR if your customers have links to the
old page on their sites.
If the latter is a problem fair enough, but if you have changed all the
internal links and this is the only place that links exist pointing to
the content then your version of the rewrite is all thats needed, no 301
etc... since nowhere relevant will the old link exist. SEO is a funny
game, arm waving and hunches, people will pay a lot for black box
services run by marketing gurus, eyes roll in the direction of M$

Here's how most of my rewrites are

    RewriteEngine On
    RewriteBase /
    RewriteRule ^$                        index.php/  [L]
    RewriteCond %{REQUEST_FILENAME}       !-f
    RewriteCond %{REQUEST_FILENAME}       !-d
    RewriteRule (.*)                      index.php/$1  [QSA,L]

then the application logic takes care of the URLs so no other rewrites
are ever needed, query strings become obselete as the URL maps to
variables; sometimes I might add regular expressions and conditions into
the above so that apache has first bite at the URL, and then php also
checks it over, no harm in that methinks.

good luck



-- 
Matthew Farey



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] avoiding a redirect loop with rewrites

Posted by Josh Trutwin <jo...@trutwins.homeip.net>.
On Thu, 22 Feb 2007 21:36:03 +0000
matt farey <ma...@gmail.com> wrote:

> RewriteEngine On
> ReWriteCond %{REQUEST_FILENAME} pid5.html$
> ReWriteCond %{QUERY_STRING} !stop=yes
> ReWriteRule . /products.html [R=301]
> ReWriteRule ^products.html$ /pages/pid5.html?stop=yes [L,QSA]

Thanks Matt - I'll give that a try to see if it fits the works.  I
assume this would still work too if I wanted to be as specific as
possible:

ReWriteCond %{REQUEST_FILENAME} pages/pid5.html$

> I'll be embarrassed if it works, the easier way would be to let
> your CMS handle this internally using PHP perhaps, then the rewrite
> rules can be simple,a dnt eh CMS ensures the right url in all the
> links.

The CMS is written in PhP and I am trying to catch all instances of
the old URL where I can and replacing with the new URL (the rules are
also stored in a db for quick lookup).  So *internally* all the
pidXX.html references should be taken care of.

> Where does the bookmark come from, chase down all the places where
> they can see that link, and force it to be the new url, all seems a
> bit backward. Next time tell your boss, "look you employed me to do
> this job, so trust me to do it" sounds like a micro manager!

Well - technically not a manager - a reseller I think.  Here's
verbatim what they told me (old pages = pages/pidXX.html):

"If we are changing url paths, we will need to setup 301's in
their .htaccess files from the old pages to the 'new' pages. Thats
the only way to insure the rankings wont drop.  ...  You want to
avoid systems that create two separate instances of a page that have
identical content but are addressable from different URLs. Duplicate
content risks the appearance of "spamming" the search index."

The big concern I think is Search Engines finding two URLs to the
same page and somehow punishing the site because of it.  They might
have pages/pid5.html as the products page and then crawl the site to
find the link products.html is the same page.  

I don't know enough about SEO to say much about this.

Thanks,

Josh

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] gui for apache under windows

Posted by Tony Stevenson <to...@pc-tony.com>.
Tim,

There is no official Windows GUI that you can use to edit the Apache 
HTTPD config file. You need to edit it using notepad/wordpad/a.n.other 
text editor.

On the other hand there is no official GUI tool for any platform, some 
have tried, and failed in areas that others have succeeded and vice-a-versa.

The short and tall of it is, edit via the text config file, you will not 
only learn more, you may also obtain a better understanding of how the 
config file is laid out.


--
Tony

p.s.  There are some tools available, but they are mainly Unix based 
(webmin being the most common)


Tim Thorburn wrote:
> Hello,
> 
> I apologize if this question has been asked before, however I have not 
> found any mention of it within the archives.  As the subject says, I am 
> looking for a gui to configure Apache 2.2.24 under Windows - I've done 
> some searching online and all I can find are either Linux only options, 
> or packages that have not been updated in 3+ years that do not seem to 
> know Apache2 even exists.
> 
> This is just a testing server for some design work I'm doing, so 
> security isn't necessarily a concern for me.  If anyone has any 
> recommendations, it would be much appreciated.
> 
> TIA
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] gui for apache under windows

Posted by Tim Thorburn <im...@nwconx.net>.
Hello,

I apologize if this question has been asked before, however I have not 
found any mention of it within the archives.  As the subject says, I am 
looking for a gui to configure Apache 2.2.24 under Windows - I've done 
some searching online and all I can find are either Linux only options, 
or packages that have not been updated in 3+ years that do not seem to 
know Apache2 even exists.

This is just a testing server for some design work I'm doing, so 
security isn't necessarily a concern for me.  If anyone has any 
recommendations, it would be much appreciated.

TIA

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] avoiding a redirect loop with rewrites

Posted by matt farey <ma...@gmail.com>.

Josh Trutwin wrote:
> Hi,
>
> I'm working for a small company that uses a custom CMS.  When
> customers create pages in the CMS a file gets created based on the
> page's id number - for example:
>
> www.mysite.com/pages/pid5.html
>
> I've pushed some code into the CMS that lets the site admin create a
> nice URL for each page so you get something nicer like:
>
> www.mysite.com/products.html
>
> The pid5.html file still exists but now they should see the new URL
> everywhere on the site.  The rule I used for this was:
>
> RewriteRule ^products.html$ /pages/pid5.html [L,QSA,NC]
>
> One of the folks in charge here wanted to make sure that for
> existing sites anyone who still had the old URL bookmarked or search
> engines that have the old URL gets a permanent redirect to the new
> one to avoid having two URLs that go to the same place.  I thought
> I'd do this with a RedirectPermanent, but when I do that I get a
> redirect loop.  I also tried creating rewrite rules for the pid5.html
> page - no luck.
>
> Basically, is there any way to have a rewrite rule map a new URL name
> to an existing page, and also a permanent redirect for anyone using
> the old URL name.  I would have to think this has come up before but
> wasn't able to find anything.
>
> Thanks for your help,
>
> Josh
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
>   

This is possible of course, but IMHO it isnt what rewrites are for, it
is muddle headed to refuse to serve a valid url until the browser has
been redirected to an invalid resource which serves the url in the
background. It wont solve the issue of outdated bookmarks, it just
further confuses the older client because they see things refreshing to
a new URL, when they were used to the old one (these are the clients
that apparently notice these things)
This is the reason it isn't everywhere in the docs ;) By the way it
causes another HTTP request, and repeats of all the associated linked files:

RewriteEngine On
ReWriteCond %{REQUEST_FILENAME} pid5.html$
ReWriteCond %{QUERY_STRING} !stop=yes
ReWriteRule . /products.html [R=301]
ReWriteRule ^products.html$ /pages/pid5.html?stop=yes [L,QSA]

I'll be embarrassed if it works, the easier way would be to let your CMS
handle this internally using PHP perhaps, then the rewrite rules can be
simple,a dnt eh CMS ensures the right url in all the links.

Where does the bookmark come from, chase down all the places where they
can see that link, and force it to be the new url, all seems a bit
backward. Next time tell your boss, "look you employed me to do this
job, so trust me to do it" sounds like a micro manager!

-- 
Matthew Farey




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org