繁体   English   中英

httpd 2.4 mod_rewrite将别名目录发送到浏览器url

[英]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.sh503

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.

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