![]() |
|
|||||||
| 建站交流 讨论网站建设的基本方法、技巧、空间问题讨论、域名交流、 资源分享、技术交流,站长们经常进来看看噢! |
|
|
Thread Tools | Display Modes |
|
#1
IP: 49.82.32.201
|
|||
|
|||
|
If you have a standard Linux server, you probably have Apache as the actual Web server software. The other alternatives include Lighttpd (pronounced “Lighty”) and Nginx (pronounced “Engine-X”) but they’re not overly common. If you have a file called “.htaccess” in your “public_html” folder, you know you’ve got Apache running on your server.
.htaccess file 301 Redirects taught on this page include: Redirect a Single Page Redirect an Entire Site Redirect all subpages without redirecting the entire domain Redirect a site to WWW Redirect a site to Non-WWW Note: If you end your old site or folder URL with a / it will keep the names and folders that are accessed intact so if you create a redirect from www.website.com/data/ to www.kickasswebsite.com/data/ and a visitor attempts to go to www.website.com/data/oldpage.htm will become www.kickasswebsite.com/data/oldpage.htm. This ability will help you most when you need to transfer a site to a new domain. Also, I am using FileZilla as my FTP program and these instructions are tailored to it. If you use a different FTP program, the processes may vary. How To Redirect a single page Log in to your web hosting account in your FTP program and navigate to the /public_html folder. Right-Click on the file called “.htaccess”. Choose “View/Edit”. Right at the top, copy in one of the lines below that starts with “Redirect 301″. Change the “/oldpage.html” to the page or folder you want to redirect from. Change the http://www.yoursite.com/newpage.html” to the page or folder you want visitors to go to. Save the document. Close the file editor. Click in the FTP Editor. Click on “Finish editing and delete local file.” Code:
The Code Required: Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html Redirect 301 /oldpage2.html http://www.yoursite.com/folder/ Redirect 301 / http://www.yoursite.com/blog/ Log in to your web hosting account in your FTP program and navigate to the /public_html folder. Right-Clisk on the file called “.htaccess”. Choose “View/Edit”. Right at the top, copy in one of the lines below that starts with “Redirect 301″. Change the http://website.com/” to the page or folder you want visitors to go to. Save the document. Close the file editor. Click in the FTP Editor. Click on “Finish editing and delete local file.” Code:
The Code Required: Redirect 301 / http://website.com/ If you need to 301 redirect all the subpages of a domain but don’t want to redirect www.domain.com itself, you can use the following bit of code. Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Some people want to have the WWW at the beginning of your URL. Other people think it looks grittier not to have it. Whichever you prefer, and thankfully it doesn’t truly matter, is up to you. Doing a redirect from websitecom to wwwwebsitecom is fine as long as it is a correct 301 redirect. It’s also perfectly acceptable to redirect wwwwebsitecom to websitecom. It’s just best if you do choose 1 way or the other for SEO because Google can view website.com and www.website.com as separate sites. This means that if you have incoming links going to both website.com and www.website.com there’s a chance that they will both build up different pages in Google’s eyes. So to correct that, here’s how you can make everything look uniform using the htaccesss file. Redirect to WWW with the htaccesss file To edit the .htaccess file, follow the instructions above and insert the following code at the head of the file. Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule (.*) http://www.website.com/$1 [R=301,L]
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^website.com$
RewriteRule (.*) http://website.com/$1 [R=301,L]
If you have multiple pages that come up with a 404 error and you don’t want to take the time to redirect each and every one, I highly recommend entering the following code into your .htaccess file. It’ll automatically redirect all 404 error pages to your home page, thus saving your SEO and keeping people on your site. Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| FIX - Vbulletin redirecting to filestore72.info / url123.info etc - Redirect Google | Mabton | vBulletin技术交流 | 0 | 2014-05-31 06:55 AM |
| Redirect home.php | topvip | X-Cart | 1 | 2013-11-08 10:24 AM |
| htaccess 301 redirect tutorial | yahoo | 服务器环境搭建 | 0 | 2009-09-06 12:45 AM |
| 301 Redirect 永久重定向的实现 | yahoo | 搜索引擎优化 | 0 | 2008-01-21 12:51 AM |
| How to redirect more domains in one folder via .htaccess | smiling | 建站交流 | 1 | 2007-08-18 01:14 AM |