.htaccess 将URL重写到https://www

.htaccess 将URL重写到https://www,.htaccess,.htaccess,我看过几个关于将所有URL重写到的主题 但我最终还是没能进入工作, 我刚才的htaccess代码如下: RewriteEngine On RewriteRule ^([a-zA-Z]+)/rss\.xml/?$ rss.php/$1 [NC,L] RewriteRule ^fa/post/([0-9]+)/([^/]*)/?$ /post.php/$1 [NC,L] RewriteRule ^fa/product/([0-9]+)/([^/]*)/

我看过几个关于将所有URL重写到的主题 但我最终还是没能进入工作, 我刚才的htaccess代码如下:

RewriteEngine On  
RewriteRule    ^([a-zA-Z]+)/rss\.xml/?$    rss.php/$1    [NC,L]
RewriteRule    ^fa/post/([0-9]+)/([^/]*)/?$    /post.php/$1     [NC,L]
RewriteRule    ^fa/product/([0-9]+)/([^/]*)/?$    /product.php/$1     [NC,L]
RewriteRule    ^fa/subject/([0-9]+)/([^/]*)/?$    /subject.php/$1      [NC,L]
RewriteRule    ^fa/gallery/([0-9]+)/([^/]*)/?$    /gallery.php/$1      [NC,L]
RewriteRule    ^fa/poll/([0-9]+)/([^/]*)/?$    /poll.php/$1      [NC,L]
RewriteRule    ^fa/([^/]*)$    index.php/$1   [NC,L]
RewriteRule    ^sitemap\.xml$    sitemap.php   [NC,L]
RewriteRule    ^posts(/?)$    posts.php   [NC,L]
RewriteRule    ^tag/([^/]*)/?$    /tag.php?value=$1     [NC,L]
RewriteRule    ^cat/([0-9]+)/([^/]*)/?$    /tag.php?value=$2     [NC,L]


RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://www.zanjan.org%{REQUEST_URI} [R=301,L,NE] 
除了这两个URL之外,所有URL似乎都可以正常工作:

zanjan.org/cat/SomeNumberHere/SomeWordHere
zanjan.org/tag/SomeWordHere
例1:

例2:

上面的页面不会转到,使用代理,它们甚至会向我显示以下错误(chrome):

和FireFox中的空页


如何使它们工作?

将您的
https
重定向规则移动到“在线重写引擎”下方,并在其他浏览器中进行测试。通常,重定向规则应置于所有内部重写规则之上:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://www.zanjan.org%{REQUEST_URI} [R=301,L,NE] 

RewriteRule ^([a-zA-Z]+)/rss\.xml/?$    rss.php/$1    [NC,L]
RewriteRule ^fa/(post|product|subject|gallery|poll)/([0-9]+)/([^/]*)/?$ /$1.php/$2 [NC,L]

RewriteRule ^fa/([^/]*)$ index.php/$1   [NC,L]

RewriteRule ^sitemap\.xml$ sitemap.php   [NC,L]

RewriteRule ^posts(/?)$ posts.php   [NC,L]

RewriteRule ^tag/([^/]*)/?$ /tag.php?value=$1     [NC,L]

RewriteRule ^cat/([0-9]+)/([^/]*)/?$ /tag.php?value=$2     [NC,L]

此外,我还将您的5条类似重写规则合并为一条规则。

将您的https重定向规则移动到
行的
重写引擎下方,并在不同的浏览器中进行测试。谢谢您anubhava!我只是把最后4行移到了第一行,效果很好!请添加答案,以便我将其标记为已接受。。
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://www.zanjan.org%{REQUEST_URI} [R=301,L,NE] 

RewriteRule ^([a-zA-Z]+)/rss\.xml/?$    rss.php/$1    [NC,L]
RewriteRule ^fa/(post|product|subject|gallery|poll)/([0-9]+)/([^/]*)/?$ /$1.php/$2 [NC,L]

RewriteRule ^fa/([^/]*)$ index.php/$1   [NC,L]

RewriteRule ^sitemap\.xml$ sitemap.php   [NC,L]

RewriteRule ^posts(/?)$ posts.php   [NC,L]

RewriteRule ^tag/([^/]*)/?$ /tag.php?value=$1     [NC,L]

RewriteRule ^cat/([0-9]+)/([^/]*)/?$ /tag.php?value=$2     [NC,L]