Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite needed due to spammed content

mod_rewrite needed due to spammed content

         

asinah

3:57 am on Jun 6, 2004 (gmt 0)

10+ Year Member



Hi everyone,
We developed a hotel inhouse hotel database and the structure is of the following:

/dir1/language/1290.php

We want to redirect 14900 records to a new domain
[newdomain.com...] and issue a 301 permanent redirect. (Last week we made a search and noted that our pages are showing up on keyword searches which we held until recently at Google and AJ.

The file 1290.php is an example and the records end at 14900.

I am using many permanen redirects and I recently saw that a solution was posted to it. Last night I searched and browsed WW for around two hours but I could find the post.

Can someone please point me to the right thread.

Thanks
Asinah

jdMorgan

4:33 am on Jun 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To clarify, do you want to redirect *all* pages on the old domain to a new domain, or redirect only pages
1.php through 14900.php, or redirect only pages named <any_number>.php to the new domain?

The only way to find the right solution is to fully-define the problem.

Jim

asinah

7:05 am on Jun 6, 2004 (gmt 0)

10+ Year Member



Hi Jim,
Thanks for your quick reply.

It should be any number <any_number>.php but the directory on the remote server has a different name and it should generate the 301 redirect so that google and the other SE's would find the new pages. We don't want to redirect all pages to the new server and only the pages in /dir1/. The other directories would not be affected.

example :

/dir1/<any_number>.php to [newserver.com...]

I am sure it was discussed last week but I have searched for some times on this forum with google without success.

If you can point me to the right thread I would be very grateful.

jdMorgan

2:14 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the problem is that this is a basic rewrite, and there are so many variations on it that it would be impossible to find the thread by title, because the title would be ambiguous.

All you need to do is redirect all files in that one directory that match the <any_number>.php pattern to another domain. As such, look for "permanent redirect domain rewriterule [google.com]". Post your best effort at writing the code and your test results, and we'll help you get it working if you have problems.

Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

Jim

asinah

3:10 am on Jun 7, 2004 (gmt 0)

10+ Year Member



Hi Jim,
I came up with the following code but I am looking for a reference to the numbers.

RewriteEngine on
RewriteBase /dir1/
rewriterule ^dir2/(.+).html [newserver.com...] [L,R=301]

I think my problem is in the rewritrule but I will keep trying and learning.

jdMorgan

4:03 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One to five digits, each ranging from 0 to 9 inclusive:

RewriteRule ^dir2/([0-9]{1,5})\.html$ http://www.newserver.com/dir2/$1 [L,R=301]

I don't know about your RewriteBase, though - that doesn't look quite right with your RewriteRule, based on your original description, which called for /dir1 in your RewriteRule, and a RewriteBase of "/" or none.

Jim

asinah

6:41 am on Jun 7, 2004 (gmt 0)

10+ Year Member



I think I did a mistake:

Can you tell me Jim if this code would work?

RewriteRule ^dir/([0-9]{1,5})\.php$ [newserver.com...] [L,R=301]

Currently the files reside on an old server at
htt://oldserver.com/dir/*.php and all files will be redirected to htt://oldserver.com/dir2/*.html

/dir and /dir2 are different names

I really appreciate your feedback.

jdMorgan

3:19 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That should work. Try it late at night, or whenever your traffic is minimum.

Jim

asinah

2:03 am on Jun 8, 2004 (gmt 0)

10+ Year Member



Jim,
thanks for all your help everything works. Just tried it out.

Thanks
Asinah

asinah

3:22 am on Jun 8, 2004 (gmt 0)

10+ Year Member



Jim,
Just tested the directories under languages and they don't work

Doesn't work: [newdomain.com...]

This does work
[newdomain.com...] (English is the default language) but as soon I am going into the 2nd level directory it shows a mysql error.

eg..
[newdomain.com...]

Do I need to set a base directory? On the new domain I don't use the structure of dir2/language but only use dir2/

I ahd to disable the modifications as the 6 languages are down for the momwent.

jdMorgan

5:21 am on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to specify the desired rewrite for your 'languages' URLs, since you haven't mentioned them before. The problem should be easy to fix, once it's defined.

Problems like this are most easily discussed if you include a comprehensive list of all needed rewrites from the start.

Right now we have:
/dir/0.php$ ------> [newserver.com...]
/dir/99999.php$ --> [newserver.com...]

What else is needed to include 'language' URLs?

Jim

asinah

6:13 am on Jun 8, 2004 (gmt 0)

10+ Year Member



Hi Jim,
the problems are as following:

/dir/0.php$ --> [newserver.com...]
/dir/99999.php$ --> [newserver.com...]

The above works already for the english version.

We have the following directories inside /dir

/dir/chinese/99999.php$ --> [newserver1.com...]

/dir/deutsch/99999.php$ --> [newserver2.com...]

/dir/japanese/99999.php$ --> [newserver3.com...]

/dir/french/99999.php$ --> [newserver4.com...]

/dir/italiano/99999.php$ --> [newserver5.com...]

/dir/espaniol/99999.php$ --> [newserver6.com...]

Do I need to set a base directory as the old structure is different from the new site structure?

Asinah

jdMorgan

2:56 pm on Jun 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the new directory structure does not relate directly to the old, you'll need a ruleset for each language. This could be avoided if you used (for example) the first two letters of the language on the new server, instead of directory numbers. Then you could simply back-reference those letters and use two rewriterules to handle all languages.

However, the solution with your current directory structure would simply be one rule for each language:


RewriteRule ^dir/([0-9]{1,5})\.php$ http://www.newserver.com/dir2/$1\.html [L,R=301]
RewriteRule ^dir/chinese/([0-9]{1,5})\.php$ http://www.newserver.com/dir3/$1\.html [L,R=301]
RewriteRule ^dir/deutch/([0-9]{1,5})\.php$ http://www.newserver.com/dir4/$1\.html [L,R=301]
RewriteRule ^dir/japanese/([0-9]{1,5})\.php$ http://www.newserver.com/dir5/$1\.html [L,R=301]
RewriteRule ^dir/french/([0-9]{1,5})\.php$ http://www.newserver.com/dir6/$1\.html [L,R=301]
RewriteRule ^dir/italiano/([0-9]{1,5})\.php$ http://www.newserver.com/dir7/$1\.html [L,R=301]
RewriteRule ^dir/espaniol/([0-9]{1,5})\.php$ http://www.newserver.com/dir8/$1\.html [L,R=301]

Put these rules in order, from most-frequently accessed language to least-frequently accessed. This will improve overall performance.

And just for reference, the solution using the two-letter method would be:


RewriteRule ^dir/([0-9]{1,5})\.php$ http://www.newserver.com/dir2/$1\.html [L,R=301]
RewriteRule ^dir/([a-z]{2})[^/]+/([0-9]{1,5})\.php$ http://www.newserver.com/$1/$2\.html [L,R=301]

RewriteBase is only needed on servers where the filepath to a resource is different from the local URL-path to that resource. Remember that URLs need not have anything in common with the filesystem architecture on your server. URLs and filepaths are two ways of specifying how to find a resource, but URLs are used on the Web, while filepaths are used inside the server. Mod_rewrite takes action at exactly the point where the URL-to-filepath translation happens, and you can use it to change the URL-path to a very different filepath.

I never use RewriteBase unless I can't get the code to work without it, and then I simply review the Apache error log to see what I need to include in RewriteBase. The error log will indicate where the server attempted to fetch the resource from, and comparing that to where it actually resides on the server will give the necessary RewriteBase path.

Jim

asinah

5:06 pm on Jun 8, 2004 (gmt 0)

10+ Year Member



Dear Jim,
I changed the code as suggested and it works now.

Thanks again for your help and I will certainly visit this forum again to hopefully learn more about the hidden secrets of Apache.

Asinah