.htaccess - 使用 .htaccess 清除 URL

标签 .htaccess mod-rewrite seo rewrite html5boilerplate

我是网页设计的新手,一直无法弄清楚这一点..

我正在使用 HTML5Boilerplate 作为我的新网站的模板。模板附带的 .htaccess 文件重写了“www.example.com -> example.com”。这对我来说很好。

现在我想重写我所有的/index.html -> 根文件夹并清除末尾的斜杠。

例如:当有人键入或链接指向“www.mysite.com/subfolder/index.html”(或 .htm)时,这将被重写为“mysite.com/subfolder”。

此时代码为:

# ----------------------------------------------------------------------
# Start rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and

# features. FollowSymLinks must be enabled for this to work.

# Some cloud hosting services require RewriteBase to be set: goo.gl/HOcPN
# If using the h5bp in a subdirectory, use `RewriteBase /foo` instead where
# 'foo' is your directory.

# If your web host doesn't allow the FollowSymlinks option, you may need to
# comment it out and use `Options +SymLinksIfOwnerMatch`, but be aware of the
# performance impact: http://goo.gl/Mluzd

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
  RewriteEngine On
# RewriteBase /
</IfModule>

# ----------------------------------------------------------------------
# Suppress or force the "www." at the beginning of URLs
# ----------------------------------------------------------------------

# The same content should never be available under two different URLs -
# especially not with and without "www." at the beginning, since this can cause
# SEO problems (duplicate content). That's why you should choose one of the
# alternatives and redirect the other one.

# By default option 1 (no "www.") is activated.
# no-www.org/faq.php?q=class_b

# If you'd prefer to use option 2, just comment out all option 1 lines
# and uncomment option 2.

# IMPORTANT: NEVER USE BOTH RULES AT THE SAME TIME!

# ----------------------------------------------------------------------

# Option 1:
# Rewrite "www.example.com -> example.com".

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>

# ----------------------------------------------------------------------

# Option 2:
# Rewrite "example.com -> www.example.com".
# Be aware that the following rule might not be a good idea if you use "real"
# subdomains for certain parts of your website.

# <IfModule mod_rewrite.c>
#   RewriteCond %{HTTPS} !=on
#   RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
#   RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# </IfModule>

最佳答案

如果您认真对待使用 HTAccess,那么有一个非常可靠的引用资料可以解决所有可能出现的小问题。它不是免费的 - 但会收回成本。

http://htaccessbook.com

关于.htaccess - 使用 .htaccess 清除 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16604295/

相关文章:

apache - 子域 https www 到非 www

apache - 如何在 .htaccess 中为特定 IP 地址设置 cookie

pdf - SEO 最好直接链接到文件,或者有 Action 而不是返回 FileResult?

php - 链接到另一个 Action

.htaccess - 如何强制 .com 域重定向到 .tld

apache - 对主域文件强制使用 SSL,但不对任何文件夹内的文件强制使用 SSL

php - URL重写和URL重定向

mod-rewrite - Lighttpd 配置,. (点)在我的查询字符串中导致 404

Wordpress SEO - 同一页面上的所有内容或单独的帖子以获得更好的排名?

seo - Liferay 7 ,网页内容的摘要和标签未添加为元描述和关键字