我的.htacess中有以下代码,但它不能正常工作。是不是因为mod-rewrite没有"on",如果是这样,我怎么检查?
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\$ $1.php [nc]我想重命名我的地址,例如:
http://www.abc.com -> http://www.abc.com
http://abc.com -> http://www.abc.com
http://www.abc.com/123.html -> http://www.abc.com/123
http://www.abc.com/12-12-12.html -> http://www.abc.com/12-12-12
http://subdomain.abc.com/123.html -> http://subdomain.abc.com/123
基本上删除了扩展,并确保其www完好无损。
编辑:
它被重写成
Options +FollowSymlinks
RewriteEngine on
RewriteCond % ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^(.*).php $1但还是不能工作
发布于 2012-10-03 13:12:31
第1步。
更改所有链接以从链接中删除.html。确保您已关闭Multiviews:
Options -Multiviews第2步。
当主机名中缺少www时,您需要规则来重定向浏览器:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]第3步。
当使用删除了扩展名的.html或.php请求URL时,您需要规则来重定向浏览器:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.(php|html?)
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ /%2 [L,R=301]第4步。
如果请求实际上是针对php或html文件,则需要在内部重写URI的规则:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule ^(.*)$ /$1.htm [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [L].htaccess
所以总而言之,你应该在你的htaccess中有这些规则(抛弃你可能已经有的试图解决这个问题的规则):
# Make sure Multiviews is off
Options -Multiviews
# turn on rewrite engine
RewriteEngine On
# Redirect requests that are missing www and not a subdomain
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# Redirect if requests is for a .htm, .html, or .php
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.(php|html?)
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ /%2 [L,R=301]
# rewrite to the proper extension if such a file exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule ^(.*)$ /$1.htm [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [L]所以总而言之:
如果浏览器地址栏显示:http://example.com/index.html,它将被重定向到http://www.example.com/index
index.php,如果存在)上的内容。地址栏仍然是unchanged.
/images/image.png看到图片。地址栏仍然是unchanged.
发布于 2012-09-23 23:31:39
删除.html
RewriteRule ^(.*).html $1 [L,QSA]添加www。
RewriteCond % ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]发布于 2012-10-02 17:27:50
您的网站位于哪个主机上?您确定启用了mod-rewrite吗?如果没有激活,你有没有联系你的主人把它戴上?
androbin (https://stackoverflow.com/a/12553613/1713771)之前发布的解决方案是正确的。
https://stackoverflow.com/questions/12553569
复制相似问题