网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > 建站交流
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

建站交流 讨论网站建设的基本方法、技巧、空间问题讨论、域名交流、
资源分享、技术交流,站长们经常进来看看噢!

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   IP: 49.82.32.201
Old 2014-06-15, 07:52 PM
Packard Packard is offline
初级会员
 
Join Date: 2009-01-09
Posts: 2
Packard 现在声名狼藉
Default .htaccess 301 Redirect

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/
How To Redirect an entire site
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/
Redirect Only Subpages

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]
Redirect to WWW or to non-WWW

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]
Redirect to non-WWW with the htaccesss file
Code:
RewriteEngine On
 RewriteCond %{HTTP_HOST} !^website.com$
 RewriteRule (.*) http://website.com/$1 [R=301,L]
Redirect 404 Errors to home page

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]
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

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

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:56 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.