简体   繁体   English

htaccess 在带走 www 时恢复到 php url。 或 https

[英]htaccess reverting to php url when taking away www. or https

I have a problem with my htaccess file rewrite rules.我的 htaccess 文件重写规则有问题。 I am forcing HTTPS, WWW.我正在强制使用 HTTPS,WWW。 and a trailing slash.和尾部斜线。 The redirects work fine, if I remove WWW.如果我删除 WWW,重定向工作正常。 or HTTPS then it redirects with them.或 HTTPS 然后它与它们一起重定向。 Nice.好的。

However, if I'm somewhere like "/home/" appended on the url, and I remove either HTTPS or WWW.但是,如果我在 url 上附加了“/home/”之类的地方,并且我删除了 HTTPS 或 WWW。 it will then end up like "//index.php/?module=home" instead of "/home/" appended.然后它会像“//index.php/?module=home”而不是附加的“/home/”一样结束。

Noticeably, it has the correct behaviour for adding the trailing slash.值得注意的是,它具有添加尾部斜杠的正确行为。 That does not mess it up.那不会把事情搞砸。

Full rules:完整规则:

RewriteRule ^image_prox/([%\w\.-_]*)$ /includes/image_proxy.php?url=$1 [N,NC]

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

RewriteRule ^mailinglist/$ /index.php?module=mailing_list [N]

RewriteRule ^articles/$ /index.php?module=home [N]

RewriteRule ^all-articles/$ /index.php?module=home&displayall [N,QSA]

RewriteRule ^all-articles/page\=([0-9]+)/$ /index.php?module=home&page=$1&displayall [N]

RewriteRule ^admin/$ /index.php?module=home [L]

RewriteRule ^latest-comments/$ /index.php?module=comments_latest [N]

RewriteRule ^latest-comments/page=([0-9]+)/$ /index.php?module=comments_latest&page=$1 [N,NC,QSA]

RewriteRule ^home/banned/$ /index.php?module=home&message=banned [N]

RewriteRule ^irc/$ /index.php?module=irc [N]

RewriteRule ^register/$ /index.php?module=register [N]

RewriteRule ^about-us/$ /index.php?module=about_us [N]

RewriteRule ^private-messages/$ /index.php?module=messages [N]

RewriteRule ^submit-article/$ /index.php?module=submit_article&view=Submit [N]

RewriteRule ^submit-article/error\=(.+?)?$ /index.php?module=submit_article&view=Submit&error=$1 [N,NC,QSA]

RewriteRule ^contact-us/$ /index.php?module=contact [N]

RewriteRule ^email-us/$ /index.php?module=email_us [N]

RewriteRule ^support-us/$ /index.php?module=support_us [N]

RewriteRule ^articles/$ /index.php?module=home [N]

RewriteRule ^articles/(.+?)\.([0-9]+)/$ /index.php?module=articles_full&title=$1&aid=$2 [N,NC,QSA]

RewriteRule ^articles/([0-9]+)/$ /index.php?module=articles_full&aid=$1 [N,NC,QSA]

RewriteRule ^articles/(.+?)\.([0-9]+)/error=(.+?)/?$ /index.php?module=articles_full&aid=$2&title=$1&error=$3 [N,NC,QSA]

RewriteRule ^articles/(.+?)\.([0-9]+)/page\=([0-9]+)/?$ /index.php?module=articles_full&aid=$2&title=$1&page=$3 [N,NC,QSA]

RewriteRule ^articles/(.+?)\.([0-9]+)/comment_id\=([0-9]+)/?$ /index.php?module=articles_full&aid=$2&title=$1&comment_id=$3 [N,NC,QSA]

RewriteRule ^articles/(.+?)\.([0-9]+)/article_page\=([0-9]+)/?$ /index.php?module=articles_full&aid=$2&title=$1&article_page=$3 [N,NC,QSA]

RewriteRule ^home/page\=([0-9]+)/$ /index.php?module=home&page=$1 [N]

RewriteRule ^private-messages/page\=([0-9]+)/$ /index.php?module=messages&page=$1 [N,NC,QSA]

RewriteRule ^private-messages/compose/(\d+)*/$ /index.php?module=messages&view=compose [N]

RewriteRule ^private-messages/compose/user\=([0-9]+)/$ /index.php?module=messages&view=compose&user=$1 [N,NC,QSA]

RewriteRule ^private-messages/([0-9]+)/$ /index.php?module=messages&view=message&id=$1 [N,NC,QSA]

RewriteRule ^private-messages/([0-9]+)/page\=([0-9]+)/$ /index.php?module=messages&view=message&id=$1&page=$2 [N,NC,QSA]

RewriteRule ^profiles/([0-9]+)/$ /index.php?module=profile&user_id=$1 [N,NC,QSA]

RewriteRule ^profiles/([0-9]+)/comments/$ /index.php?module=profile&view=more-comments&user_id=$1 [N,NC,QSA]

RewriteRule ^profiles/([0-9]+)/comments/page\=([0-9]+)$ /index.php?module=profile&view=more-comments&user_id=$1&page=$2 [N,NC,QSA]

RewriteRule ^users/statistics/$ /index.php?module=statistics [N,NC,QSA]

RewriteRule ^users/statistics/statid=([0-9]+)/$ /index.php?module=statistics&statid=$1&act=pick [N,NC,QSA]

RewriteRule ^articles/category/(.+?)/page\=([0-9]+)/$ /index.php?module=articles&view=cat&catid=$1&page=$2 [N,NC,QSA,B]

RewriteRule ^articles/category/(.+?)/$ /index.php?module=articles&view=cat&catid=$1 [N,NC,QSA,B]

RewriteRule ^itemdb/([0-9]+)/$ /index.php?module=items_database&view=item&id=$1 [N,NC,QSA]

RewriteRule ^itemdb/developer/([0-9]+)/$ /index.php?module=items_database&view=developer&id=$1 [N,NC,QSA]

RewriteRule ^itemdb/anticheats/([0-9]+)/$ /index.php?module=items_database&view=anticheats&id=$1 [N,NC,QSA]

RewriteRule ^steam-tracker/$ /index.php?module=steam_linux_share [N,NC,QSA]

RewriteRule ^steamplay/$ steamplay.php [N,NC,QSA]

RewriteRule ^steamplay/reports/([0-9]+)/$ steamplay_reports.php?id=$1 [N,NC,QSA]

RewriteRule ^steamplay/reports/([0-9]+)/page=([0-9]+)/$ steamplay_reports.php?id=$1&page=$2 [N,NC,QSA]

RewriteRule ^db/$ itemdb.php [N,NC,QSA]

RewriteRule ^free-games/$ free_games.php [N]

RewriteRule ^itemdb/steamid/([0-9]+)/$ itemdb.php?steamid=$1 [N,NC,QSA]

RewriteRule ^sales/page=([0-9]+)/$ /sales.php?page=$1 [N,NC,QSA]

RewriteRule ^sales/([0-9]+)/$ /sales.php?sale_id=$1 [N,NC,QSA]

RewriteRule ^sales/message=(.+?)/?$ /sales.php?message=$1 [N,NC,QSA]

RewriteRule ^sales/$ sales.php [N]

  Redirect 301 /podcast_rss_ogg.php /podcast_rss.php?format=ogg

  # make sure www. is always there
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

  # force trailing slash
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)([^/])$        /$1$2/ [L,R=301]
  
  # if requested url does not exist pass it as path info to index.php
  RewriteRule ^$ index.php?/ [QSA,L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) index.php?/$1 [QSA,L]

Your external redirects (non-www to www and HTTP to HTTPS) are in the wrong place.您的外部重定向(非 www 到 www 和 HTTP 到 HTTPS)位置错误。 These need to go before the existing rewrites, at the top of the file.这些需要在现有的重写之前,在文件的顶部。

You will need to clear your browser cache since the erroneous 301 (permanent) redirect will have been cached by the browser.您需要清除浏览器缓存,因为错误的 301(永久)重定向已被浏览器缓存。 Test first with 302 (temporary) redirects to avoid caching issues.首先使用 302(临时)重定向进行测试以避免缓存问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM