【问题标题】:vhosts.conf RewriteRulevhosts.conf 重写规则
【发布时间】:2014-06-03 03:25:54
【问题描述】:

我的网站位于/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>

【问题讨论】:

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


    【解决方案1】:

    您可以将此 sn-p 放在您的 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>
    

    【讨论】:

    • 你用什么网址来测试它?
    • 127.0.0.1/site-dir/home/exampletwo,还告诉我是否必须指定某个地方 AllowOverride 或其他什么?
    • 如果 DocumentRoot 是 /srv/http/site-dir 那么 URL 应该是 http://127.0.0.1/home/exampletwo
    • 我相信 %{REQUEST_FILENAME} 应该可以工作,但您始终可以使用更可靠的检查:RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    • 谢谢。现在更好了,因为在我进行更改之前,我没有渲染我的 public/style.css。 ;)
    猜你喜欢
    • 2014-06-06
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 2010-11-20
    • 2012-11-21
    相关资源
    最近更新 更多