RewriteRule 未正確重寫 URL

RewriteRule 未正確重寫 URL

我有以下虛擬主機檔案:

<IfModule !wsgi_module>
  LoadModule wsgi_module modules/mod_wsgi.so
  WSGISocketPrefix run/wsgi
</IfModule>

<VirtualHost *:80>
  RewriteEngine On
  RewriteLog "/var/log/httpd/rewrite_log"
  RewriteLogLevel 1
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
</VirtualHost>

<VirtualHost *:443>
  ServerName https://tendril-api.dev.adnxs.net
  ServerAlias 06.tendril-api.dev.nym2.adnexus.net/api

  RewriteEngine  on
  RewriteRule    ^docs$  docs/  [R]
  ... 
  # SSL & WSGI Setup
</VirtualHost>

由於某些原因,我的docs重寫規則根本沒有生效。為什麼是這樣?我的 *:80 VirtualHost 中的 HTTP-->HTTPS 重寫規則運作正常。我正在做一些非常相似的事情。

這是否與不同虛擬主機中有兩個不同的重寫規則有關?

有任何想法嗎?

答案1

按照http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule:-

匹配的是什麼?

在 VirtualHost 上下文中,模式最初將與主機名稱和連接埠之後、查詢字串之前的 URL 部分進行配對(例如「/app1/index.html」)。

您的模式與「docs」的確切 URL 相符。實際的 URL 可能是“/docs”,因此在“^”後面添加“/”可能會起作用:-

RewriteRule    ^/docs$  docs/  [R]

相關內容