我是 apache 的新手,我有以下目录结构:
html
|-- moodle
|-- singapur
|-- app
|-- public
|-- js
|-- css
|-- img
|-- index.php
我需要从 重定向www.mywebpage.com/singapur
到www.mywebpage.com/singapur/public
.htaccess
文件夹中的位置是singapur
:
Options -Indexes
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /singapur/
RewriteRule .* public/$1 [L]
</IfModule>
.htaccess
文件夹中的位置是public
:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /singapur/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
文件moodle.conf
:
<VirtualHost *:80>
ServerName webpageexample.cl
ServerAlias www.webpageexample.cl
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/moodle
<Directory /var/www/html/moodle/>
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
但是,当我尝试从网络浏览器访问时webpageexample.cl/singapur
,我获得以下内容
Forbidden
You don't have permission to access /singapur/ on this server.
在Apache日志中:
Cannot serve directory /var/www/html/moodle/singapur/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
谢谢
答案1
您可以使用该RedirectionMatch
指令强制 Apache 将用户发送到其他地方。
RedirectMatch 301 ^(.*)$ http://www.anotherserver.com$1
点击这里了解更多知识。