我希望你能帮助我解决这个问题。我正在尝试设置我的apache服务器重定向,但没有成功。我试图立即这样做:
如果可能,所有重定向都应使用R = 301。
这是我到目前为止所做的,但它不起作用。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteRule ^portfolio/(\d+)/(.*) portfolio.php?id=$1 [QSA,L]
RewriteRule ^portfolio portfolio.php [QSA,L]
RewriteRule ^about about.php [QSA,L]
请帮我解决这个问题。我花了很多时间阅读,但从未做过正确的事。主要问题是Google Crawlers将我的网页识别为重复,并且我有我想要解决的规范网址问题。
感谢您的帮助!
不完美,但从概念上讲,这将照顾其中的一部分。将http重定向到https,解决1,2和3。
在Linux上的/ etc / apache2 / sites-enabled中找到的文件
Listen 443
Listen 80
IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName example.com
redirect / https://example.com
</VirtualHost>
<VirtualHost*:80>
ServerName www.example.com
redirect / https://example.com
</VirtualHost>
<VirtualHost*:443>
ServerName www.example.com
redirect / https://example.com
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
**Put all the other stuff you need here**
</VirtualHost>
根据您的配置,有很多事情需要考虑。
修改文件后,您需要重新启动Apache。
试试这个 :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(php|html)[\s?/] [NC]
RewriteRule ^ /%1%2 [R=301,L]
RewriteCond %{QUERY_STRING} ^id=(\d+)&t=(.+)
RewriteRule ^(.*)$ /$1/%1/%2 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\/]+)/(\d+)/(.*)$ /$1.php?id=$2&t=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*) /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*) /$1.html [L]
RewriteEngine on
之后的前三行是为了确保所有请求都是https://example....
接下来的两行是删除两个qazxsw poi扩展。
接下来的两行捕获任何查询字符串html & php
并从外部将其重写为/portfolio?id=1&t=max
。
接下来的两行捕获任何URI,如/portfolio/1/Max
,并在内部将其重写为原始路径。
其余行将重定向其余的URI并检查它们是否在内部是/portfolio/1/Max
。
注意:清除浏览器缓存然后测试