Forum Moderators: phranque
Search Engines are still pointing to the old pages, how do I redirect them to the new ones?
Old pages looked like
www.mydomain.com/home.php?page=mypage
New pages look like
www.mydomain.com/index/template1.php?page=mynewpage
I have tried a 301 redirection with php, but that has to be inserted into the old home.php page, pointing to template1.php.
It works but I am loosing the variable so the redirection loads into the template the default page of my php scipt.
Therefore I am loosing the redirection to the specific variable/page which is of course relevant in order to redirect the Search to a page with the same content as the old one.
Any way to solve this problem?
Jim
I have tried the simple redirect in the .htaccess
Redirect /olddirectory/oldfile.php?page=mycontent [yoursite.com...]
This doesn't work and the people at the hosting company say I have to upgrade my plan because my current plan do not support mod rewrite.
Can this be made to work or is it wrong anyway.
This redirection must be done on many pages
Is there any way to obtain the same redirection with php?
I know this is not the forum to ask this question...
Just
RewriteRule ^old_url$ http://www.example.com/new_url [R=301,L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
RewriteRule ^http://mysite.com/home.php?page=oldpage$ [mysite.com...] [R=301,L]
Is this correct?
Now, two questions:
1) Can i repeat this for as many page as I need?
2) Do i have to add this line in the .htaccess file located in the root of my website, independently of where the page to redirect is located?
RewriteCond %{QUERY_STRING} ^page=oldpage$
RewriteRule ^http://mysite.com/home.php$ http://www.example.com/indexes/newone.php?page=newpage [R=301,L]
> 2) Do i have to add this line in the .htaccess file located in the root of my website, independently of where the page to redirect is located?
The code must be in the same directory as the requested local URL-path indicates, or in any HTTP-accessible directory above that directory. The server follows the requested URL-path and executes .htaccess directives along that path, so the code needs to be located where it will get executed.
If you have lots of page IDs to replace, you can use a little back-reference 'trick' to make a crude mapping function, reducing multiple RewriteCond/RewriteRule pairs to multiple RewriteConds followed by a single rule:
RewriteCond %{QUERY_STRING}<>newpage1 ^page=oldpage1<>(.+)$ [OR]
RewriteCond %{QUERY_STRING}<>newpage2 ^page=oldpage2<>(.+)$ [OR]
RewriteCond %{QUERY_STRING}<>newpage8 ^page=oldpage8<>(.+)$ [OR]
RewriteCond %{QUERY_STRING}<>newpage9 ^page=oldpage9<>(.+)$
RewriteRule ^http://mysite.com/home.php$ http://www.example.com/indexes/newone.php?page=%1 [R=301,L]
Jim
first of all let me thank you for your time.
Well I have tried what you suggest.
Here's what I done.
I added the following line to an .htaccess file which I placed in the root of my website.
----------------
RewriteCond %{QUERY_STRING} ^page=people$
RewriteRule ^http://www.mysite.com/home.php$ [mysite.com...] [R=301,L]
----------------
I have tried to access the page that should trigger the redirection but I get an internal server error
----------------
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
----------------
I get the same error whatever page I try to access on my website no matter if old ones or new ones.
If I rename (or remove) the .htaccess averything goes back to normal.
Looks like the server panicks when it reads my .htaccess.....
Any idea?
Did I get something wrong?
Thanks
If you have no previously-working mod_rewrite rules, then you'll need to enable mod_rewrite before using it. This is done (typically) by adding
Options +FollowSymLinks
RewriteEngine on
If you check your server error log file, it will likely contain this same diagnosis.
Also note that if you are changing only the page URL and not the query string, then you can pass the existing query through mod_rewrite unchanged by using the simpler rule:
RewriteCond %{QUERY_STRING} ^page=people$
RewriteRule ^http://www.mysite.com/home.php$ http://www.example.com/indexes/about.php [R=301,L]
For more information, please see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
-------
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=people$
RewriteRule ^http://www.mysite.com/home.php$ [mysite.com...] [R=301,L]
--------
Unfortunately I get the same error as before.
And I can't check the log file since I have no access to the server only to my website plan, I'm on a virtual hosting plan.
Your RewriteRule pattern cannot contain "http://example.com" -- mod_rewrite requires a local URL-path only there.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=people$
RewriteRule ^home\.php$ http://www.example.com/indexes/about.php?page=people [R=301,L]
Jim
I am on a cobalt raq server and the cobalt panel doesn't offer any control of the server, since I am not the server admin I have no password for it, just my site admin, users, email etc.
The people of the hosting co has been trying to force me to upgrade to Ensim, I don't know if this will help, if I will have access to the apache log file on Ensim.
Problem is I have to modify all the scripts with absolute server path if I change machine and that'd be a nightmare.
Well maybe it's time to do it, or evaluate a different provider with a better service.
Thanks so much for the help anyway.
Jim
Some of them are self-installing and required absolute server path at installation looking like
/home/site45/web/cgi-bin/
so you understand changing server path is a disaster, as I don't even have an idea of the use the script did of this path.
That'd be great if I could solve this problem!
And what about the path to perl? Can that be managed in the same way?
I hope you can answer one more question.
I actually did a mistake in the path of the page to redirect since the home.php is not in the root but in a subfolder (en).
So the page I have to redirect is in
www.mysite.com/en/home.php?page=people
and not in
www.mysite.com/home.php?page=people
now, you say it is required local URL path so what do I have to change the path to?
The path you suggested in your post was:
^home\.php$
I don't understand how the path must be formed and the use of the slash between the name of the file home and the file extension .php.....
What am I supposed to use now?
^en/home\.php$ ?
Thanks