Hostwinds 教程

寻找结果为:


目录


简单重定向:
更多高级选项:
对于WordPress用户:

如何编辑.htaccess文件

标签: htaccess 

简单重定向:
更多高级选项:
对于WordPress用户:

请注意,编辑.htaccess文件是非常无情的。 即使是最轻微的错误,也可能导致您的网站显示内容不正确或根本不显示。

编辑.htaccess文件时, 总是 制作备份副本,以便在出现问题时可以恢复工作配置。

Linux系统区分大小写,甚至包括URL。

如果您在上传文件时遇到问题,则可能必须将其命名为htaccess.txt,然后在服务器上重命名它。

在以下示例中,ReplaceWithYourDomain.com应该用您的域名替换

简单重定向:

# Permanent Redirect:
Redirect 301 / http://ReplaceWithYourDomain.com/
# Temporary Redirect (Use this if you plan to move back to the original site to save your SEO scores):
Redirect 302 / http://ReplaceWithYourDomain..com/
# Redirect the index page to a subdirectory:
Redirect /index.html http://ReplaceWithYourDomain.com/subdirectory/
# Redirect from an old sub-directory or file to a new sub-directory or file:
Redirect /OldSubdirectory/OldFile.html http://ReplaceWithYourDomain.com/NewSubdirectory/NewFile.html
# Define an alternate index file:
DirectoryIndex mynewindex.html

更多高级选项:

# Redirect YourDomain.com to www.YourDomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect www.YourDomain.com to YourDomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^ReplaceWithYourDomain.com$ [NC]
RewriteRule ^(.*)$ http://ReplaceWithYourDomain.com/$1 [R=301,L]
# Redirect an open connection to your secure SSL connection:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.ReplaceWithYourDomain.com/$1 [R,L]
# Hide contents of a directory if index file does not exist
Options -Indexes

对于WordPress用户:

如果您的站点停止工作,则应首先检查.htaccess文件。

将.htaccess文件重命名为.htaccess_bak,然后浏览到您的站点。

这在很多时候都有效。

如果重命名.htaccess文件修复您的网站,则可以将以下标准WordPress .htaccess配置放入新的.htaccess文件中。

以下是默认WordPress .htaccess文件的内容:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]  
# END WordPress

撰写者 Hostwinds Team  /  八月 21, 2017