Forum Moderators: phranque

Message Too Old, No Replies

Need to rediect specific page on URL to another page

Have numerous virtual hosts this applies to

         

Thanasus

12:51 am on Feb 2, 2004 (gmt 0)

10+ Year Member



I am trying to figure out an easy way to do this...

I have about 400 domains which all had a page
www.widget.com/profile.html

I made some server changes and now all the profile pages are in a subdir like this
www.widget.com/profile/index.html

Problem is the old profile for many of the sites is already indexed in google. I would like to do a redirect, directing people to the new URL and transferring the PR as well. The problem is I dont want to put in redirect codes for over 400 domains!

Is there a catchall that can be done which would redirect

www.*.com/profile.html

to

www.*.com/profile/index.html

coyote

1:51 am on Feb 2, 2004 (gmt 0)

10+ Year Member



This should work if you put it on top-level (and all domains are on same server):

RewriteEngine on
RewriteCond (profile\.html)
RewriteRule /profile/index.html$ [R=301,L]

edited for grammar and to work across multiple domains

Thanasus

3:21 am on Feb 2, 2004 (gmt 0)

10+ Year Member



Hmm... I get a syntax error

RewriteCond: bad argument line '(profile\.html)'

coyote

3:37 am on Feb 2, 2004 (gmt 0)

10+ Year Member



Try it without the ( ) and/or without the \

jdMorgan

4:02 am on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanasus,

For use in httpd.conf, something like this:


RewriteEngine on
RewriteRule ^/profile\.html$ http://%{HTTP_HOST}/profile/index.html [R=301,L]

For use in .htaccess, omit the leading slash on "^/profile\.html$"

This keeps whatever the requested domain name was, which is what I assume you wanted to do.

Jim

Thanasus

8:32 am on Feb 2, 2004 (gmt 0)

10+ Year Member



jd, you are correct.. i am trying to have it backrefernce the domain name

in one of the domains, i have an .htaccess file:
"
ErrorDocument 404 /index.html
RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.widget.com [NC]
RewriteRule ^(.*)$ [widget.com...] [R,L]
"

Basically, it prepends the 'www' subdomain. Now when I add your snippet of code, it works:
"
ErrorDocument 404 /index.html
RewriteEngine on
RewriteRule ^profile\.html$ [%{HTTP_HOST}...] [R=301,L]
RewriteCond %{HTTP_HOST}!^www.widget.com [NC]
RewriteRule ^(.*)$ [widget.com...] [R,L]
"

*please note I had to remove the initial backslash from the pattern match. it was failing to catch anything for "^\profile" but did work for "^profile"

Now obviously, I dont want to got through every .htaccess file an add the rewrite code. I tried putting in each virtual host directive
"
<VirtualHost 192.168.0.2>
ServerAdmin joe@widget.com
DocumentRoot /www/web44
ServerName www.widget.com
ServerAlias widget.com
ErrorLog /var/log/host.widget.com-error_log
CustomLog /var/log/host.widget.com-access_log combined
RewriteEngine on
RewriteRule ^profile\.html$ [%{HTTP_HOST}...] [R=301,L]
</VirtualHost>
"

But when in the virtual host directly in the .htaccess file it does not work at all. Any help would be appreciated.
"

jdMorgan

3:11 pm on Feb 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanasus,

As noted in my previous post, there is a subtle difference between .htaccess and httpd.conf contexts. In httpd.conf, RewriteRule can "see" the leading slash on a URI; In .htaccess, it cannot. So therefore, patterns in .htaccess do not start with slash, and in httpd.conf, they do.

I'm not sure if that is the problem you're seeing. If not, it's likely that your code is not being executed because the server does not go through the directory where the code is in order to server the requested resource.

Jim

Thanasus

5:54 pm on Feb 2, 2004 (gmt 0)

10+ Year Member



Thanks! I was copying and pasting so much I forgot about the preceeding /

On a related question, if I may, one of the pages I am also trying to redirect has a hypen

[widgets.com...]
to
[widgets.com...]

I am using the httpd.conf file and I modified your line to make

RewriteRule ^/search-profile\.php$ [%{HTTP_HOST}...] [R=301,L]

However it won't fly I also tried escaping the hypen but no go:
RewriteRule ^/search\-profile\.php$ [%{HTTP_HOST}...] [R=301,L]

jdMorgan

9:15 pm on Feb 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I doubt that the hyphen has anything to do with the problem. More likely, the pattern does not match the actual path seen by httpd.conf... It might need to have '/user/httpdocs' or similar in front of it, for example.

Look at your error logs if you're getting an error response; They may be of great help to determine the porblem.

Jim