[英]httpd 2.4 mod_rewrite sends alias directory to browser url
We have httpd 2.4.29, with custom *.conf and .htaccess. 我们具有自定义* .conf和.htaccess的httpd 2.4.29。
myUrl.com/old/folder/alpha.sh
, the page displays the alpha.sh
as expected myUrl.com/old/folder/alpha.sh
,页面按预期显示alpha.sh
myUrl.com/old/folder/alpha
, sends a redirect to the browser so the url changes to myUrl.com/home/my/new/folder/www/alpha.sh
with a 503
myUrl.com/old/folder/alpha
,发送重定向到浏览器这样的URL改变myUrl.com/home/my/new/folder/www/alpha.sh
与503
myUrl.com/old/folder/beta
, (beta does not exist), keeps the url as expected and generates a forbidden You don't have permission to access /beta.sh on this server.
myUrl.com/old/folder/beta
不存在),按预期保留url并生成禁止的URL。 You don't have permission to access /beta.sh on this server.
What is wrong with the configs below that causes the execution directory to be returned with a 503 when a *.sh file exists? 下面的配置有什么问题,当存在* .sh文件时,导致执行目录返回503?
NB:if we change the type of rewrite to RewriteRule ^(.+)$ $1.html [L]
and cgi-script is not used, then the rewrite works as expected. 注意:如果我们将重写类型更改为
RewriteRule ^(.+)$ $1.html [L]
并且未使用cgi-script,则重写将按预期进行。
myUrl.conf 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 /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 /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]
The RewriteBase
should set to /old/folder
(same as the alias definition), and it would be a good practice to check if the .sh
file exists with this RewriteCond %{REQUEST_FILENAME}.sh -f
RewriteBase
应该设置为/old/folder
(与别名定义相同),并且最好的做法是检查.sh
文件是否存在此RewriteCond %{REQUEST_FILENAME}.sh -f
See also: Apache Virtual Host with Alias 另请参阅: 具有别名的Apache虚拟主机
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.