微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

删除域后的斜线

这是我的.htaccess文件

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Remove multiple slashes anywhere in URL RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . %1/%2 [R=301,L] # Never use www prefix! RewriteCond %{HTTP_HOST} ^www.domain.org [NC] RewriteRule (.*) http://domain.org/$1 [R=301,L] # Remove multiple slashes after domain RewriteRule ^/(.*)$ http://domain.org/$1 [R=301,L] # Remove trailing slash in some cases RewriteRule ^(.*).css/$ http://domain.org/$1.css [L,R=301] RewriteRule ^(.*).js/$ http://domain.org/$1.js [L,R=301] RewriteRule ^(.*).jpg/$ http://domain.org/$1.jpg [L,R=301] RewriteRule ^(.*).jpeg/$ http://domain.org/$1.jpeg [L,R=301] RewriteRule ^(.*).png/$ http://domain.org/$1.png [L,R=301] RewriteRule ^(.*).gif/$ http://domain.org/$1.gif [L,R=301] RewriteRule ^(.*).xml/$ http://domain.org/$1.xml [L,R=301] # Force trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.PHP RewriteCond %{REQUEST_URI} !(.*).css RewriteCond %{REQUEST_URI} !(.*).js RewriteCond %{REQUEST_URI} !(.*).jpg RewriteCond %{REQUEST_URI} !(.*).jpeg RewriteCond %{REQUEST_URI} !(.*).png RewriteCond %{REQUEST_URI} !(.*).gif RewriteCond %{REQUEST_URI} !(.*).xml RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://mydomain.org/$1/ [L,R=301] #Removes access to the system folder by users. #Additionally this will allow you to create a System.PHP controller,#prevIoUsly this would not have been possible. #'system' can be replaced if you have renamed your system folder. RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.PHP?/$1 [L] #Checks to see if the user is attempting to access a valid file,#such as an image or css document,if this isn't true it sends the #request to index.PHP RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.PHP?/$1 [L] # MIME types AddType text/css .css AddType text/javascript .js # Enable compression AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/x-css text/x-javascript text/x-js text/htm application/x-javascript application/javascript application/js application/x-js image/png image/gif image/jpg image/jpeg #Skip browsers with kNown problems browserMatch ^Mozilla/4 gzip-only-text/html browserMatch ^Mozilla/4.0[678] no-gzip browserMatch bMSIE !no-gzip !gzip-only-text/html PHP_flag display_errors on </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.PHP </IfModule>

但是,当我去**///// ,尾部的斜线不会消失。 我究竟做错了什么?

在mod_rewrite正则expression式中使用escape(。)字符

在Apacheconfiguration中检测Apache版本?

RewriteRule for .html / RK = 0 / RS =

Apache 2的mod_rewrite和PHP修改htaccess的$ _SERVER 值?

htaccess使用参数redirecturl

当准备好时,%{REQUEST_URI}变量会减少额外的斜线。 所以RewriteCond %{REQUEST_URI} ^(.*)//(.*)$永远不会匹配,因为对于像http://domain.org////这样的请求,REQUEST_URI变量被简化为/ 。 尝试使用THE_REQUEST变量:

RewriteCond %{THE_REQUEST} ^([AZ]{3,9}) (.*)//([^ ]*) RewriteRule ^ %2/%3 [R=301,L]

此外,当重写规则在htaccess文件中时,前缀(前导斜杠)从请求URI中被剥离,所以规则RewriteRule . %1/%2 [R=301,L] RewriteRule . %1/%2 [R=301,L]永远不会匹配,因为正则表达式 至少需要一个字符才能匹配。 当URI为/并且前导斜线被剥离时,用于在URL中匹配的URI是空白字符串。 所以使用^ ,或(。*) ,或者类似于“一切都不包括”的东西的正则表达式需要被使用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐