Forum Moderators: phranque
I'm relatively new to webmastering so please forgive any stupid questions.
What I want to do:
I would like to redirect a webpage from (an example)
www.example.com/thispage
to
www.example.com/otherpage
What I am using now:
I have made a .htaccess file for my root folder
with this script.
(.htaccess being the most search engine friendly way of doing this, or at leas I read.)
Redirect 301 /thispage http://www.example.com/otherpage/otherpage.htm
The problem:
Seems to work ok except for the fact that the script ADDS A TRAILING SLASH to the redirected address which leads to 404 missing page.
Redirects me to
http://www.example.com/otherpage/otherpage.htm/
instead of
http://www.example.com/otherpage/otherpage.htm
(without the trailing slash)
Is this a common problem? Any help would be greatly appreciated.
Thanks. Muji
www.example.com/thispage.htm
I've changed the name of the page (not foreseeing this problem) and would like the above link to go to the new page
www.example.com/otherpage.htm
The problem is that the script redirects me to the new page AND ADDS a trailing slash
www.example.com/otherpage.htm/
which leads me to a missing page error.
I have links on several websites that go to this page
www.example.com/thispage.htm
I've changed the name of the page (not foreseeing this problem) and would like the above link to go to the new page
www.example.com/otherpage/otherpage.htm
The problem is that the script redirects me to the new page AND ADDS a trailing slash
www.example.com/otherpage/otherpage.htm/
which leads me to a missing page error.
Wildbest- Thanks for your suggestion. That's the structure of the code I am presently using. but the script leads to an address and ADDS a TRAILING SLASH.
your suggestion...
[I've suggested you use this code:
Redirect 301 /thispage.htm http://www.example.com/otherpage/otherpage.htm]
takes me to an error page that says the page does not exist.
I should add...
the reason I didn't add the htm in the first place was because the original designer of the webpages had a structure where he would name his file
index.htm and put it in a folder called 'thispage' then use
www.example.com/thispage to link to it.
which would direct him to the index page within the folder 'this page'
therefore i am using...
Redirect 301 /thispage http://www.example.com/otherpage/otherpage.htm
which takes me to this page
http://www.example.com/otherpage/otherpage.htm/
Which is great EXCEPT that it ADDS A TRAILING SLASH AT THE END OF THE ADDRESS that I do not want.
which then gives me a 404 error message.
If I can somehow remove the / (TRAILING SLASH) it would work.
but the .htaccess code somehow writes in that TRAILING SLASH automatically.
Hope this makes sense.
My redirect is working now. Yes!
Now I would like to add more webpage redirects.
I tried just adding another line.
Redirect 301 /thispage/ http://www.example.com/otherpage/otherpage.htm
Redirect 301 /thispage2/ http://www.example.com/otherpage2/otherpage2.htm
This addition of the second redirect
leads to each of the page redirects to... "The server encountered an internal error or misconfiguration and was unable to complete your request."
Can't figure this one out.
Help please.
- change misleading titles of your folders and pages to, say http://www.example.com/otherfolder/otherpage.htm or http://www.example.com/folder1/page1.htm or http://www.example.com/folder2/page2.htm
- You might need putting your access file in /thisfolder/ and /thisfolder2/ folders and not in the root.
- Instead of http://www.example.com/otherfolder/otherpage.htm why don't you just put all your files in the root folder like http://www.example.com/otherpage.htm?
- finally, if more complex redirect rules are needed you might want to use mod_alias RedirectMatch rules or mod_rewrite.
[httpd.apache.org...]
The redirect is for people who still have the old URL bookmarked, and for search engines who will keep coming back trying the old URL potentially forever.
For people clicking links within your site to go to other pages within your site, they should get directly to the page and should not pass through a redirect.
www.example.com/thispage
would open the index page inside.
After lots of research and your nice comments I have decided that, though it may take a lot of time, It would be best to go back to the original address/naming convention. They have 10 years of links directed to the older links. I've only updated the names in the last couple of months.
It seems that for more than 30 redirects the 'redirect 301' method isn't the best one to use.
Thanks for your help.
If you are redirecting an index page URL, then you'll want to be more open about the syntax of the incoming URL requests that will work. You'll want to redirect for all of these:
/folder
/folder/
/folder/index.html
/folder?someparam
/folder/?someparam
/folder/index.html?someparam
as well as for URLs including port numbers and so on.
You'll also need it to redirect whether the original request was for www or for non-www URLs.
In that case a one line
RewriteRule [R=301,L] would be useful. .
If there is an "easy" relationship between all of the old names and all of the new names, one line of code could redirect for all 30 files/folders at the same time.
.
If Google has indexed any of your new URLs while you were experimenting, you might now need a redirect to tell them to go back to the old URL. Never test this stuff on a live site. Set up a Password protected "test" sub-domain where you can test code out first.
RedirectMatch 301 /thispage(/.*)?$ http://www.example.com/otherpage/otherpage.htm
RedirectMatch 301 /thispage2(/.*)$ http://www.example.com/otherpage2/otherpage2.htm
Options +FollowSymLinks -MultiViews
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /thispage/?[^\ ]*\ HTTP/
RewriteRule ^thispage/?$ http://www.example.com/otherpage/otherpage.htm [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /thispage2/?[^\ ]*\ HTTP/
RewriteRule ^thispage2/?$ http://www.example.com/otherpage/otherpage2.htm [R=301,L]
Jim