这是我的. htaccess。
DirectorySlash Off
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.php\ HTTP/
RewriteRule ^(.*)\.php$ /$1 [R=301,L]
# Ensure www. and https
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Rewrite the URL to append a trailing slash to directories (internally)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*[^/])$ $1/ [L]
虽然这似乎是正常工作,而在网络浏览器上冲浪,问题出现时,我们的SEO团队爬网使用第三方工具,如尖叫青蛙。网址出现如下:
*.mywebsite.com
*.mywebsite.com/blogs
*.mywebsite.com/blogs/blog-1
*.mywebsite.com/about-us
....
*.mywebsite.com//
*.mywebsite.com//blogs
*.mywebsite.com//blogs/blog-1
*.mywebsite.com//about-us
....
我不想两个斜杠后域的网址。我尝试了许多解决方案,可在互联网上,但他们都没有工作。
1条答案
按热度按时间pkmbmrz71#
您可以使用此重定向规则从URL中的任何位置删除
//
:正则表达式模式
\s[^?]*//
在匹配THE_REQUEST
变量(表示原始Apache请求)中的?
(查询字符串的stat)之前匹配//
。请注意,默认情况下,
RewriteRule
中的模式通过Apachemod_rewrite
引擎去除了多个/
。