vhosts.conf RewriteRule

时间:2014-04-18 15:25:04

标签: apache .htaccess mod-rewrite httpd.conf

我的网站位于/srv/http/site-dir/,其根目录.htaccess包含以下内容:

Options -MultiViews

RewriteEngine On

Options -Indexes

RewriteBase /site-dir/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

它以这种方式工作,但是现在我想将这些规则移到httpd-vhosts.conf文件中,所以我需要更改它以使其在那里工作,从而避免使用我读过的.htaccess如果您可以访问主.conf文件,那么可以进行床上练习吗?

编辑: 将其输入我的httpd-vhosts.conf按照建议尝试,但没有成功。

<VirtualHost *:80>
    DocumentRoot "/srv/http/site-dir"
    ServerName project-site-dir.my
    ServerAlias www.project-site-dir.my

    Options -MultiViews -Indexes

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^/site-dir/(.+)$ /site-dir/index.php?url=$1 [QSA,L]

    ErrorLog "/var/log/httpd/project-site-dir.my-error_log"
    CustomLog "/var/log/httpd/project-site-dir.my-access_log" common
</VirtualHost>

1 个答案:

答案 0 :(得分:1)

您可以将此代码段放在httpd-vhosts.conf文件中:

<VirtualHost *:80>
    DocumentRoot "/srv/http/site-dir"
    ServerName project-site-dir.my
    ServerAlias www.project-site-dir.my

    Options -MultiViews -Indexes

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^/(.+)$ /index.php?url=$1 [QSA,L]

    ErrorLog "/var/log/httpd/project-site-dir.my-error_log"
    CustomLog "/var/log/httpd/project-site-dir.my-access_log" common
</VirtualHost>