【问题标题】:What are the initial settings required to be done for mod_rewrite?mod_rewrite 需要做哪些初始设置?
【发布时间】:2012-02-10 12:03:54
【问题描述】:

mod_rewrite 需要做哪些初始设置?

因为找不到合适的文章而问这个问题。
我认为这个问题会被否决。

好的,为了避免被否决,

我尝试了这些设置,但 mod_rewrite 似乎不起作用:

LoadModule rewrite_module modules/mod_rewrite.so 

<Directory />
    Options -Indexes +FollowSymLinks
    RewriteEngine On
    AllowOverride All
</Directory>

<Directory "/mysite">
    Options -Indexes +FollowSymLinks
    AllowOverride All  # was suggested to do this from many sites.  
                       # So mod_rewrite could work
    Order allow,deny
    Allow from all
    RewriteEngine On
</Directory>


<VirtualHost 'ip-addr'>
    .
    .
    .
    Options -Indexes +FollowSymLinks
    RewriteEngine On
</VirtualHost>

httpd -t -D DUMP_MODULES | grep rewrite

有输出:

 rewrite_module (shared)
Syntax OK

我的DocumentRoot/mysite。 在/mysite/xhprof 中设置xhprof

xhprof 的index 文件位于/mysite/xhprof/xhprof_html

/mysite/xhprof/xhprof_html/.htaccess 中有这个。

RewriteEngine On
RewriteBase   /xhprof

当我尝试访问 &lt;myurl&gt;/xhprof/xhprof_html/ 时,url 不会被重写。

【问题讨论】:

  • I think this question will be down-voted. 我认为这是一个准确的看法。 ;) 但是,您可以通过“设置”澄清您的意思来防止这种情况发生。你想达到什么目标?
  • @pekka :) 添加了更多细节。
  • 我没有看到您的 .htaccess 中定义的任何 RewriteRules。你期待什么重写?
  • @UlrichPalha 雅,确实知道.. 解决它的某个时候回来。这个问题现在是无声的。不过,感谢您的帮助。

标签: apache .htaccess mod-rewrite url-rewriting apache2


【解决方案1】:

包括以下内容:

Options +FollowSymlinks
RewriteEngine on

此外,请确保在您的常规 HTTP 配置中(.htaccess 之外),您有一个 AllowOverride.htaccess 中启用您需要的任何内容。 AllowOverride FileInfoAllowOverride All - 取决于您的具体需求。

【讨论】:

  • 这里的反对票是怎么回事 - 对于这个答案和 Miro 的?这准确地回答了“mod_rewrite 需要进行哪些初始设置?”的问题。 (没有办法知道 RewriteRule 的预期不在配置中的其他地方,只是为了简洁起见没有显示......)
【解决方案2】:

你只需要在 .htaccess 中使用这个语句来打开它:

RewriteEngine on

我建议使用 unix 基本编辑器(Notepad++、VM、..)而不是 Windows 记事本,因为它会添加 unicode 字符并可能导致 500 Internal Server Error ... 所以如果您遇到该错误,只需复制您写的内容htaccess 并使用基于 linux/unix 的编辑器..

如果您仍然收到 500 错误,请在 RewriteEngine on 之前添加:

IndexIgnore *
Options -Indexes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-17
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    相关资源
    最近更新 更多