Forum Moderators: phranque
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
For use in httpd.conf, something like this:
RewriteEngine on
RewriteRule ^/profile\.html$ http://%{HTTP_HOST}/profile/index.html [R=301,L]
This keeps whatever the requested domain name was, which is what I assume you wanted to do.
Jim
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.
"
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
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]
Look at your error logs if you're getting an error response; They may be of great help to determine the porblem.
Jim