使用https重写SEO友好的url



我最近用SSL证书建立了一个域名,我想通过https而不是http访问整个网站。

我目前正在使用RewriteEngine和一个名为page.php的php脚本来处理URL参数,以便包含正确的页面内容与SEO友好的URL,如下所示。

www.example.com/page.php?venue=someplace&artist=singer

将成为:

www.example.com/someplace/singer

我的.htaccess文件包含以下内容

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ page.php?venue=$1&artist=$2&%{QUERY_STRING} [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ page.php?venue=$1&artist=$2&%{QUERY_STRING} [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?venue=$1&%{QUERY_STRING} [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?venue=$1&%{QUERY_STRING} [L]

当通过https访问站点时,重写似乎不能正常工作。用户被引导到我的404错误页面。在。htaccess文件中,将https://www.example.com/添加到page.php之前,效果不理想。相反,用户被转发到https://www.example.com/page.php?venue=test&artist=test。虽然这不是我需要的SEO友好的URL,但这个URL可以正确加载页面内容,所以只能假设问题一定在我的。htaccess文件中。

我已经搜索了解决方案,并发现以下我已经尝试包括在我的.htaccess,但没有任何成功。

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [Rs,L]

是否有人有解决方案进入我的.htaccess文件,使我能够通过https访问该网站?

让你的。htaccess像这样:

RewriteEngine On
RewriteBase /
# enforce https and www
RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,NE,R=302]
# skip further rules for files and directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# internal rewrite rules
RewriteRule ^([w-]+)/([w-]+)/?$ page.php?venue=$1&artist=$2 [L,QSA]
RewriteRule ^([w-]+)/?$ page.php?venue=$1 [L,QSA]

最新更新