[英]httpd 2.4 mod_rewrite sends alias directory to browser url
我們具有自定義* .conf和.htaccess的httpd 2.4.29。
myUrl.com/old/folder/alpha.sh
,頁面按預期顯示alpha.sh
myUrl.com/old/folder/alpha
,發送重定向到瀏覽器這樣的URL改變myUrl.com/home/my/new/folder/www/alpha.sh
與503
myUrl.com/old/folder/beta
不存在),按預期保留url並生成禁止的URL。 You don't have permission to access /beta.sh on this server.
下面的配置有什么問題,當存在* .sh文件時,導致執行目錄返回503?
注意:如果我們將重寫類型更改為RewriteRule ^(.+)$ $1.html [L]
並且未使用cgi-script,則重寫將按預期進行。
myUrl.conf
AddHandler cgi-script .sh
LoadModule cgid_module libexec/mod_cgid.so
LoadModule rewrite_module libexec/mod_rewrite.so
Alias "/old/folder" "/home/my/new/folder/www"
<Directory "/home/my/new/folder/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Options +ExecCGI
</Directory>
/home/my/new/folder/www/.htaccess
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /$1.sh [L]
/home/my/new/folder/www/alpha.sh
#!/bin/bash
# get today's date
OUTPUT="$(date)"
# You must add following two lines before
# outputting data to the web browser from shell
# script
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Demo</title></head><body>"
echo "Today is $OUTPUT <br>"
echo "Current directory is $(pwd) <br>"
echo "Shell Script name is $0"
echo "</body></html>"
RewriteBase /old/folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME}.sh -f
RewriteRule ^(.+)$ /$1.sh [L]
RewriteBase
應該設置為/old/folder
(與別名定義相同),並且最好的做法是檢查.sh
文件是否存在此RewriteCond %{REQUEST_FILENAME}.sh -f
另請參閱: 具有別名的Apache虛擬主機
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.