我已经在这里查看了几个mod_rewrite问题,但他们建议的任何内容都没有。迄今为止。
我有以下规则:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^-]*)/$ ?action=$1 [L]
## General Pages
RewriteRule ^privacy-policy/$ ?action=privacy-policy [L]
RewriteRule ^terms-conditions/$ ?action=terms-conditions [L]
RewriteRule ^about/$ ?action=about [L]
RewriteRule ^contact-us/$ ?action=contact-us [L]
RewriteRule ^sitemap.xml$ ?action=sitemap [L]
## Blog Pages
RewriteRule ^blog/$ ?action=blog [L]
RewriteRule ^blog/([a-zA-Z0-9-]+)/$ ?action=blog&category=$1 [L]
RewriteRule ^blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ ?action=blog&category=$1&id=$2&title=$3 [L]
第一个blog
规则正常,第三个blog
规则正常。
第二个blog
规则无法正常运行,假设我有以下网址:
/blog/general/
第二个blog
规则返回blog/general
作为category
的值不正确,它应该只返回general
作为category
的值
此问题仅发生在我的生产环境中,在我的本地开发环境中不会发生。
我真的很难过这个,任何建议都非常感激。
答案 0 :(得分:1)
尝试重新排序规则并将SSL
与www
规则合并,以避免多次重定向(对SEO和客户体验不利):
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
## General Pages
RewriteRule ^privacy-policy/$ ?action=privacy-policy [L]
RewriteRule ^terms-conditions/$ ?action=terms-conditions [L]
RewriteRule ^about/$ ?action=about [L]
RewriteRule ^contact-us/$ ?action=contact-us [L]
RewriteRule ^sitemap.xml$ ?action=sitemap [L]
## Blog Pages
RewriteRule ^blog/$ ?action=blog [L,QSA]
RewriteRule ^blog/([a-zA-Z0-9-]+)/$ ?action=blog&category=$1 [L,QSA]
RewriteRule ^blog/([a-zA-Z0-9-]+)/([0-9]+)-([a-zA-Z0-9-]+)/$ ?action=blog&category=$1&id=$2&title=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^-]*)/$ ?action=$1 [L,QSA]