htaccess 文件扩展名重写
的示例
任何人都有如何编写 url 文件扩展名特定重写 ... http://www.site.com/members.html 到 http://www.site.com/main
然后删除所有以 .html 结尾的文件的所有扩展名 http://www.site.com/.html 到 http://www.site.com/*
这也需要在有或没有 www 的情况下工作
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(ssss\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?ssss\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.ssss\.com$ [NC]
RewriteRule ^(.*)$ http://www.ssss.com/view/%2.html [R=301,L]
RewriteCond %{REQUEST_URI} !^files/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [L]
</IfModule>
anyone have an example of how to write url file extension
specific rewrite...
http://www.site.com/members.html to http://www.site.com/main
and then remove all extension for all files ending in .html
http://www.site.com/.html to http://www.site.com/*
also this needs to work with and without www
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(ssss\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?ssss\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.ssss\.com$ [NC]
RewriteRule ^(.*)$ http://www.ssss.com/view/%2.html [R=301,L]
RewriteCond %{REQUEST_URI} !^files/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [L]
</IfModule>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般经验法则是:首先放置更具体的规则。
假设您希望 site.com 重定向到 www.site.com:
The general rule of thumb is: put more specific rules first.
Assuming you want site.com to redirect to www.site.com: