homepage Welcome to WebmasterWorld Guest from 54.227.56.174
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewritecond to write 200+ links to homepage
glimbeek




msg:4234890
 1:44 pm on Nov 25, 2010 (gmt 0)

Hi,

I'm trying to create a rewritecond that rewrites 200+ links to the homepage aka:
RewriteCond %{REQUEST_URI} ^link-1.html [OR]
RewriteCond %{REQUEST_URI} ^aalink-2.html [OR]
...
RewriteCond %{REQUEST_URI} ^liasdnk-239.html
RewriteRule ^ [mydomain.com...] [R=301,L]

I just can't get it work...

I'm not sure I should be using %{REQUEST_URI} in the first place
And I'm stuck on how the RewriteRule them all in one go.

Any help would be greatly appreciated.

 

wilderness




msg:4234985
 5:59 pm on Nov 25, 2010 (gmt 0)

are the 200+ files all in the same directory?
do all the file names end with numbers?
Are same numbers limited to three characters?

FWIW, rewriting this many pages to a solitary page could be considered spamming by the SE's.
A better practice would be to provide a 410 and a link to the main page.

g1smd




msg:4235044
 9:21 pm on Nov 25, 2010 (gmt 0)

The code you have presented here does no rewriting at all.

It's a 301 redirect.

glimbeek




msg:4236143
 7:13 am on Nov 29, 2010 (gmt 0)

Thanks for the reply's,

All the url's are differently AKA not in the same directory.
And they need to bed a 301 redirect g1smd, sorry for using the wrong terminology.

jdMorgan




msg:4237685
 2:23 am on Dec 2, 2010 (gmt 0)

Do you have any other working rules? Have you tried a simple single-URL redirect rule?

Either you're missing the required "set-up" directives to enable mod_rewrite and turn on the rewriting engine, or your URL patterns are incorrect. Be aware that in a .htaccess context, the pattern in the RewriteRule does not start with a slash, but the pattern in a RewriteCond examining REQUEST_URI must.

So... one or more of the changes here might help:

RewriteCond %{REQUEST_URI} ^/link-1\.html$ [OR]
RewriteCond %{REQUEST_URI} ^/aalink-2\.html$ [OR]
...
RewriteCond %{REQUEST_URI} ^/liasdnk-239\.html$
RewriteRule ^ http://www.example.com/ [R=301,L]

Note also that literal periods in patterns must be escaped as shown.

Consider also such performance optimizations as:

RewriteCond $1 ^link-1$ [OR]
RewriteCond $1 ^aalink-2l$ [OR]
...
RewriteCond $1 ^liasdnk-239$
RewriteRule ^([^.]+)\.html$ http://www.example.com/ [R=301,L]

In this second example, none of the RewriteConds are processed unless the requested URL-path ends with ".html", and none of those RewriteConds needs to re-check for the .html extension if they do get executed. Since most requests to a typical site will be for images, this can make a big difference in performance.

However, note that I also agree that redirecting this many URLs to your index page is going to look spammy to the search engines at worst, and be taken as a sign of very poor site design and maintentance at best -- As Tim Berners-Lee, the inventor of the hyperlink, put it: "Cool URIs don't change [w3.org]." I would suggest picking only the top handful of URLs and redirecting only those, while generating a 410-Gone response for the rest. You get to decide what is meant by "the top URLs," though.

Jim

glimbeek




msg:4239227
 10:52 am on Dec 6, 2010 (gmt 0)

Hi Jim,

Thanks for clearing that out. I managed to get it to work with the first example you gave me.

Thanks again.

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