- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试向我的 .htaccess 添加一些代码,以将斜杠和非斜杠 url 重定向到 .html 所有 url 除了我的主页。
例如www.mydomain.com/cat/和 www.mydomain.com/cat应该重定向到 www.mydomain.com/cat.html
我已经设法将以下内容添加到我的 .htaccess 中,它将 www.mydomain.com/cat 重定向到正确的位置 www.mydomain.com/cat.html 但需要一些帮助来了解如何将斜杠版本重定向到 . html页面
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mydomain.com/$1.html [R=301,L]
我的整个 .htaccess 看起来像这样,如果有人根据上述内容对它的外观有任何建议,我们将不胜感激。
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx.xxx.xxx.xx [nc,or]
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mydomain.com/$1.html [R=301,L]
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# Pleas note that RewriteBase setting is obsolete use it only in case you experience some problems with SEO addon.
# Some hostings require RewriteBase to be uncommented
# Example:
# Your store url is http://www.yourcompany.com/store/cart
# So "RewriteBase" should be:
# RewriteBase /store/cart
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\.(png|gif|ico|swf|jpe?g|js|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php?sef_rewrite=1 [L,QSA]
</IfModule>
已解决:我刚刚添加:
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$ /$1 [R=301,L]
最佳答案
单独的规则似乎对您有用,但我认为您可以将其简化为一个规则,使用可选的斜线。您的规则将斜杠重定向到无斜杠,然后再次重定向到 .html。使用一个规则,您将只有一个重定向。
这有标准的 RewriteCond 检查它是否不是文件或文件夹,所以它不会继续重定向 .html 如果它已经是一个。然后,ReweriteRule 中的 \?
是一个可选的斜杠。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ http://mydomain.com/$1.html [R=301,L]
如果这一切都在您的域中,您可以从结果中省略它:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ /$1.html [R=301,L]
另外,请注意这将捕获并处理子文件夹,无论您是否有意如此。例如。,www.mydomain.com/animals/cat/将重定向到 www.mydomain.com/animals/cat.html
关于.htaccess 301 将非斜杠域和斜杠域重定向到 .html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16355773/
我有一个右下角倾斜的元素,我必须在其上放置一个盒子阴影。有时倾斜的 Angular 被徽章覆盖 - 我的问题不适用,如果是这样的话: 这是信息框及其边 Angular 的 (s)css 部分(还有更多
是否可以在纯 html/css 中创建类似下面的内容? 我想做这个响应式和全 (100%) 宽度(最大左 Angular 100 像素,右边最小 50 像素,类似的东西)。 最佳答案 您可以通过转换(
如何在 fabricjs 文本中为文本提供渐变或斜 Angular 效果?? http://fabricjs.com/fabric-intro-part-2/ 这里给出了形状和所有示例,我将其与文本绑
我用过: http://apps.eky.hk/css-triangle-generator/ 为彼此对 Angular 放置的两个不等边三 Angular 形生成 css: 左下三 Angular
我是一名优秀的程序员,十分优秀!