【发布时间】:2015-07-24 05:50:22
【问题描述】:
我正在使用 .htaccess 来清理我的 URL。单击 www.example.com/el-nino-effect 等不同链接时,它通常工作正常。但是,当我明确访问 www.example.com 时,它会将我带到 www.example.com/index?iden= 而不仅仅是 www.example.com。尽管它们是同一个页面,但这个主 URL 不知何故搞砸了。你能帮忙吗?
第 4 段是 .htaccess 中更清晰的 URL 代码的位置,但我仍然发布了整个文件。同样有趣的是,这个问题并没有发生在 Ubuntu 上的 Chrome 浏览器中,而是发生在 chromebook 上的 Chrome 浏览器上。
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension snippet
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
# For cleaner URLs making ?q=el-nino to /el-nino
RewriteRule ^([^/\.]+)?$ index.php?iden=$1 [L]
RewriteRule ^([^/\.]+)/?$ index.php?iden=$1 [L]
# RewriteRule ^downloads/([^/\.]+)/?$ downloads.php?id=$1 [L]
# For rewriting to HTTPS
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
【问题讨论】:
标签: php apache .htaccess url mod-rewrite