我们有httpd 2.4.29,有自定义* .conf和.htaccess。
myUrl.com/old/folder/alpha.sh
,该页面按预期显示alpha.sh
myUrl.com/old/folder/alpha
,向浏览器发送重定向,以便使用myUrl.com/home/my/new/folder/www/alpha.sh
503
myUrl.com/old/folder/beta
,(测试版不存在),按预期保留网址并生成禁止的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>"
答案 0 :(得分:0)
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
一起存在