如何在 wamp 服务器中使用 .htaccess 文件重定向
How to redirect with .htaccess file in wamp server
大家好,我正在努力阻止任何人访问我的 wamp 服务器的主页。
因此,如果有人键入 www.example.com
,那么它会显示 wamp 服务器的主页。
但如果有人试图进入 www.example.com
站点,则应将其重定向到 www.example.com/moodle
这是我目前在 .htaccess 文件中尝试的内容:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/moodle$ [NC]
RewriteRule .* /moodle [R=302,L]
</IfModule>
它似乎创建了一个不定式循环。
这是我的整个 .htaccess 文件:
# On some PHP servers it may help if this file is copied
# to the main moodle directory and renamed .htaccess
#
# As soon as you do this, check your web site. Is it
# still working OK? If you are getting a "configuration
# error" then you may need to enable overrides by editing
# the main httpd.conf for Apache and in the main server
# or virtual server area, adding something like:
#
# <Directory /web/moodle>
# AllowOverride All
# </Directory>
#
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!moodle/).*)$ moodle/ [NC,L]
</IfModule>
### Firstly, if you are using Apache 2, you need the following
### three lines to allow Apache to pass a PATH_INFO variable
### correctly for URLs like http://server/file.php/arg1/arg2
<IfDefine APACHE2>
AcceptPathInfo on
</IfDefine>
### Secondly, you can define the default files in the Moodle
### directories as follows:
DirectoryIndex index.php index.html index.htm
### Thirdly, set up some PHP variables that Moodle needs
php_flag file_uploads 1
php_flag short_open_tag 1
php_flag session.auto_start 0
php_flag session.bug_compat_warn 0
### Fourthly, sometimes Apache limits the size of uploaded files
### (this is a separate limit to the one in PHP, see below).
### The setting here turns off this limitation
LimitRequestBody 0
### These are optional - you may not want to override php.ini
### To enable them, remove the leading hash (#)
#php_value upload_max_filesize 2M
#php_value post_max_size 2M
#php_value session.gc_maxlifetime 7200
### You can change the following line to point to the
### error/index.php file in your Moodle distribution.
### It provides a form which emails you (the admin)
### about 404 errors (URL not found).
#ErrorDocument 404 http://example.org/moodle/error/index.php
### People have reported that these can help in some cases
### (unusual) when you see errors about undefined functions
#php_value auto_prepend_file none
#php_value include_path .
试试这个
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*\/index\.php?
RewriteCond %{THE_REQUEST} ^.*\/?
RewriteRule ^(.*)index\.php?$ http://www.example.com/moodle [R=301,L]
您可以在站点根目录 .htaccess 中使用此规则:
RewriteEngine on
RewriteRule ^((?!moodle/).*)$ moodle/ [NC,L]
大家好,我正在努力阻止任何人访问我的 wamp 服务器的主页。
因此,如果有人键入 www.example.com
,那么它会显示 wamp 服务器的主页。
但如果有人试图进入 www.example.com
站点,则应将其重定向到 www.example.com/moodle
这是我目前在 .htaccess 文件中尝试的内容:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/moodle$ [NC]
RewriteRule .* /moodle [R=302,L]
</IfModule>
它似乎创建了一个不定式循环。
这是我的整个 .htaccess 文件:
# On some PHP servers it may help if this file is copied
# to the main moodle directory and renamed .htaccess
#
# As soon as you do this, check your web site. Is it
# still working OK? If you are getting a "configuration
# error" then you may need to enable overrides by editing
# the main httpd.conf for Apache and in the main server
# or virtual server area, adding something like:
#
# <Directory /web/moodle>
# AllowOverride All
# </Directory>
#
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!moodle/).*)$ moodle/ [NC,L]
</IfModule>
### Firstly, if you are using Apache 2, you need the following
### three lines to allow Apache to pass a PATH_INFO variable
### correctly for URLs like http://server/file.php/arg1/arg2
<IfDefine APACHE2>
AcceptPathInfo on
</IfDefine>
### Secondly, you can define the default files in the Moodle
### directories as follows:
DirectoryIndex index.php index.html index.htm
### Thirdly, set up some PHP variables that Moodle needs
php_flag file_uploads 1
php_flag short_open_tag 1
php_flag session.auto_start 0
php_flag session.bug_compat_warn 0
### Fourthly, sometimes Apache limits the size of uploaded files
### (this is a separate limit to the one in PHP, see below).
### The setting here turns off this limitation
LimitRequestBody 0
### These are optional - you may not want to override php.ini
### To enable them, remove the leading hash (#)
#php_value upload_max_filesize 2M
#php_value post_max_size 2M
#php_value session.gc_maxlifetime 7200
### You can change the following line to point to the
### error/index.php file in your Moodle distribution.
### It provides a form which emails you (the admin)
### about 404 errors (URL not found).
#ErrorDocument 404 http://example.org/moodle/error/index.php
### People have reported that these can help in some cases
### (unusual) when you see errors about undefined functions
#php_value auto_prepend_file none
#php_value include_path .
试试这个
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*\/index\.php?
RewriteCond %{THE_REQUEST} ^.*\/?
RewriteRule ^(.*)index\.php?$ http://www.example.com/moodle [R=301,L]
您可以在站点根目录 .htaccess 中使用此规则:
RewriteEngine on
RewriteRule ^((?!moodle/).*)$ moodle/ [NC,L]