简体   繁体   中英

httpd 2.4 mod_rewrite sends alias directory to browser url

We have httpd 2.4.29, with custom *.conf and .htaccess.

myUrl.com/old/folder/alpha.sh , the page displays the alpha.sh as expected

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/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.

What is wrong with the configs below that causes the execution directory to be returned with a 503 when a *.sh file exists?

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.

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]

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

See also: Apache Virtual Host with Alias

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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