Apache-2.2

Nginx 重寫為 Apache rewriterule 的路徑

  • December 9, 2019

我有一個登陸頁面和一個文本框。他們在文本框中輸入了一些內容並被帶到 /search,我想載入 search_res.html。我的文件結構是:

/var/www/html
   index.html
   search_res.html

我已經讓它在 Nginx 上執行,但我必須遷移到 Apache。我似乎無法在 Apache 網路伺服器上執行以下 Nginx 程式碼:

location /search {
   rewrite ^/search$ /search_res.html; 
}

我已經查看了How do I Convert nginx to Apache rewrites,並添加了:

RewriteRule ^/search$ "search_res.html" [R=302,NC,L]但我仍然看到 404 錯誤。. 任何想法如何做到這一點?

虛擬主機配置如下:

<VirtualHost _default_:10002>


DocumentRoot "/var/www/html"
ServerName ${SERVER_ENV}

SSLEngine on
SSLCertificateFile "certs/mysubdomain.com.cer"
SSLCertificateKeyFile "certs/private.key"
SSLCertificateChainFile "certs/server.csr"


<FilesMatch "\.(cgi|shtml|phtml|php)$">
   SSLOptions +StdEnvVars
</FilesMatch>

<Directory "/usr/local/apache2/cgi-bin">
   SSLOptions +StdEnvVars
</Directory>

</VirtualHost>      

<Directory "/var/www/html">
   Options FollowSymLinks
   AllowOverride All
   Require all granted
   RewriteEngine   On 
   RewriteRule "^search$" "/search_res.html" [NC,L]
</Directory>

在您的nginx配置中,您使用了內部重寫,而不是302重定向,所以我猜您想要類似的東西:

RewriteEngine on
RewriteRule "^/search$" "/search_res.html" [NC,L]

<VirtualHost>標籤內。

引用自:https://serverfault.com/questions/994919