重定向有效,但不能重写规则(mod_rewrite加载)



重定向作品

Alias /www /var/www
<Directory /var/www>
        Options +FollowSymLinks
        DirectoryIndex index.php
<IfModule mod_rewrite.c>
        RedirectMatch /www/php/(.*) http://www.google.com/usingredirection/$1
</IfModule>

=> http://myserver/www/php/foo redirect to http://www.google.com/usingredirection/foo

所以:Mod_rewrite被加载(因为IfModule(并且也mod_alias

但是重写规则不起作用

<Directory /var/www>
        Options +FollowSymLinks
        DirectoryIndex index.php
<IfModule mod_rewrite.c>
        RewriteEngine on
        Rewritebase /var/www
        RewriteRule ^/www/php/(.*)$ http://www.google.com/rule1/$1 [R,L]
        RewriteRule ^(.*)$ http://www.google.com/rule2/$1 [R,L]
</IfModule>

Apache 日志说/var/www/php/foo 不存在(这是真的(但是为什么它不应用重写规则?

所有这些都在一个 *.conf 文件中。我试图在 htacess 中移动重写规则,但一旦我在其上添加重写引擎,总是抱怨选项 FollowSymLinks 或 SymLinksIfOwnerMatch 处于关闭状态,这意味着即使 FollowSymLinks 处于打开状态,也禁止 RewriteRule 指令

所以现在我只尝试使用重写规则模仿重定向

我的最终目标

/

www/php/*.php 像往常一样提供 php(和现有文件(

/

www/php/preview/* =>/www/php/preview.php?path=$1

/

www/php/* =>/www/php/index.php?path=$1

编辑:在第一条评论之后,我觉得发布整个内容可能会有所帮助

所以这里是httpd.conf。这个文件不是我做的。这是现成的NAS Duo的标准会议。我只是在我自己的 conf 的最后添加了一个包含。

httpd.conf

ServerRoot /frontview/ui/resource/html
...
Listen 80
# Please keep this LoadModule: line here, it is needed for installation.
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so
LoadModule auth_pam_module /usr/lib/apache2/modules/mod_auth_pam.so
LoadModule auth_sys_group_module /usr/lib/apache2/modules/mod_auth_sys_group.so
LoadModule apreq_module /usr/lib/apache2/modules/mod_apreq2.so
APREQ2_ReadLimit 2147483648
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
AddType application/x-httpd-php .php
PHPIniDir /etc/php5/apache2
ExtendedStatus On
User admin
Group admin
ServerAdmin admin@localhost
Options All Indexes
DocumentRoot /frontview/ui/resource/html
<Files ~ "^.ht">
    Order allow,deny
    Deny from all
</Files>
<Files ~ ".(js|jpg|jpeg|gif|html|htm|png|css)">
    Header set Pragma: public
</Files>
UseCanonicalName Off
TypesConfig /etc/mime.types
DefaultType text/plain
<IfModule mod_mime_magic.c>
    MIMEMagicFile share/magic
</IfModule>
HostnameLookups Off
...
<IfModule mod_autoindex.c>
    IndexOptions Charset=
    IndexOptions FancyIndexing NameWidth=*
    AddIconByEncoding (CMP,/images/Icons/compressed.gif) x-compress x-gzip
    ...more icons...
    AddIcon /images/Pix.gif ^^BLANKICON^^
    DefaultIcon /images/Icons/unknown.gif
    ReadmeName /html/AUTOINDEX.html
    HeaderName HEADER.html
    IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
</IfModule>
<IfModule mod_mime.c>
    AddEncoding x-compress Z
    ...more mime...
    AddType video/x-ms-wvx .wvx
    AddHandler cgi-script .cgi .sh .pl
</IfModule>
#AddDefaultCharset utf-8
<IfModule mod_setenvif.c>
    BrowserMatch "Mozilla/2" nokeepalive
    ...more browser...
    # Drop the Range header when more than 5 ranges.
    # CVE-2011-3192
    SetEnvIf Range (,.*?){5,} bad-range=1
    RequestHeader unset Range env=bad-range
</IfModule>
DAVLockDB /ramfs/WebDAVLock.db
DAVMinTimeout 600
Listen 443
SSLEngine On
SSL stuff ...
# -------------------------------------------------------------------
# Uncomment following when more graceful error message docs are used.
# Currently IE defaults it it's browser message, overriding any error
# docs we create anyway.
# -------------------------------------------------------------------
# ErrorDocument 401 /error/401.html
# ErrorDocument 403 /error/403.html
# ErrorDocument 404 /error/404.html
# ErrorDocument 500 /error/500.html
# Alias /error /frontview/ui/error
<Location />
  Options ExecCGI
  DirectoryIndex redirect.html index.html index.htm index.php
</Location>
...
<Location /index.html>
  SetHandler server-status
  Order Deny,Allow
  Deny from all
</Location> 
Alias /images/     /frontview/ui/resource/images/
...
PerlSwitches -I /etc/frontview/addons/ui
Alias /addons/ /etc/frontview/addons/ui/
Alias /admin /frontview/ui/resource/html
<Location /admin>
    DirectoryIndex index.html
    Options ExecCGI
    AuthType Basic
    AuthName "Control Panel"
    require user admin
</Location>
Alias get_handler /frontview/lib
PerlSwitches -I /frontview/lib
PerlModule Frontview
PerlModule get_handler
<Location /get_handler>
    SetHandler perl-script
    PerlHandler get_handler
    PerlSendHeader On
    Options ExecCGI
    Order allow,deny
    Allow from all
        AuthType Basic
        AuthName "Control Panel"
        require user admin
</Location>
Alias /np_handler /frontview/lib
<Location /np_handler>
    Options ExecCGI
        DirectoryIndex np_handler.pl 
    Allow from all
</Location>
LoadModule listhandler_module /frontview/lib/mod_listhandler.so
<Location /list_handler>
  SetHandler listhandler
</Location>
Alias /dir_list /frontview/lib/dir_list.pl
<Location /dir_list>
        AuthType Basic
        AuthName "Control Panel"
        require user admin
    Options ExecCGI
    Allow from all
</Location>
...
the file ends with Include /etc/frontview/apache/Virtual.conf
which is
<VirtualHost _default_:80>
  SSLEngine off
  RewriteEngine on
  RewriteRule ^/admin$ https://%{SERVER_NAME}/admin
  RewriteRule ^/admin/(.*)$ https://%{SERVER_NAME}/admin/$1 [R,L]
</VirtualHost>

然后 httpd.conf 以包含我的文件结束

Alias /www /var/www
<Directory /var/www>
        Options +FollowSymLinks
        DirectoryIndex index.php

        #redirecting works
        #RedirectMatch /www/php/(.*) http://www.google.com/redirecting/$1
        RewriteEngine on
        #rewriterule dont work
        RewriteRule ^(.*)$ http://www.google.com/rewriting/$1 [R,L]
</Directory>

我删除了重写基础,这应该是不必要的。我删除了 1 条规则以使事情更加清晰。现在我希望它能捕获所有服务器/www/php/* 并将它们重定向到 Google,但它仍然不起作用

由于/var/www是你的DocumentRoot所以你不能在重写规则中使用它们。在 Apache 配置中改用这些规则:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(.+?.php)$ http://www.google.com/rule1/$1 [R,L]
    RewriteRule ^(.*)$ http://www.google.com/rule2/$1 [R,L]
</IfModule>

最新更新