【发布时间】:2015-07-23 10:59:12
【问题描述】:
假设我有一个名为
的网站foo.com
我可以访问foo.com,它运行在根文件夹中的index.php。我的问题是:如何在不启用 htaccess 的情况下编辑 vhost 文件以启用 rewrite mod?
我的目标是能够写作
http://foo.com/bar/loremipsum/dolor
进入我的浏览器地址栏并运行 index.php,无论 url 中有多少 / 字符。我的 index.php 将处理由 /
分隔的参数我怎样才能做到这一点?
编辑: 虚拟主机文件:
<VirtualHost *:80>
ServerName myproject.com
ServerAlias www.myproject.com
ServerAdmin webmaster@localhost
DocumentRoot /opt/apps/myproject
<Directory /opt/apps/myproject>
# disable htaccess
AllowOverride None
# route everything to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [L]
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
编辑:问题,正如公认的答案所暗示的那样,该主机不包含打开重写引擎的行。这条线出现在答案中。这解决了问题。
【问题讨论】:
-
我愿意接受批评。我很乐意阅读为什么我的问题不好/没有帮助
-
在 vhost 文件中没有您要编辑的内容
need。如果启用了 mod_rewrite 模块,那么您只需在Directory指令中的特定 vhost 中添加您的规则。如果未启用该模块,则按上述添加规则。 -
我明白了。所以,如果它被启用,像这样的 RewriteRule ^(.*)$ index.php [QSA,L] 应该在目录标签中工作?
-
没错,没有什么特别需要做的。
-
而且 Apache 必须重新启动,对吧?
标签: php apache .htaccess mod-rewrite vhosts