首页 文章

redirect工作但不是rewriterule(mod_rewrite已加载)

提问于
浏览
0

重定向工作

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

但RewriteRule不起作用

<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不存在(这是真的),但为什么不应用rewriterule?

所有这些都在* .conf文件中 . 我试图在htacess中移动重写规则但是只要我在它上面添加一个重写引擎就会抱怨选项FollowSymLinks或SymLinksIfOwnerMatch关闭,这意味着即使FollowSymLinks打开也禁止使用RewriteRule指令

所以现在我只尝试使用rewriterule来模仿重定向

我的终极目标

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

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

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

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

所以这是httpd.conf . 这个文件不是我的 . 这是readyNAS Duo的标准配置 . 我刚刚在我自己的conf中添加了一个include .

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>

我删除了Rewritebase,这应该是不必要的 . 我删除了1条规则以使事情更加清晰 . 现在我希望这能 grab 所有服务器/ www / php / *并将它们重定向到谷歌但它仍然无效

1 回答

  • 2

    由于 /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>
    

相关问题