Re: avoiding a redirect loop with rewrites

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxxxxxxxxx
>    "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
> For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx
>
>
>   

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@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux