Apache的重写没有mod_rewrite的? [英] Apache rewriting without mod_rewrite?

查看:279
本文介绍了Apache的重写没有mod_rewrite的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阿帕奇怎么能不重写mod_rewrite的启用或配置的网址?

How can Apache be rewriting URLs without mod_rewrite enabled or configured?

我正在从我的开发服务器重新设计网站。我使用的网站部分的目录结构,但我正在考虑切换到URL重写,并把相关的文件,在该网站的根目录下。

I'm working on a site redesign from my development server. I was using a directory structure for site sections, but I am considering switching to URL rewriting and putting related files in the site's root.

例如,有关网页有一个名为有关该子目录包含其担任的的index.php当请求 http://www.example.com/about 。我打算改变这种做法,从站点的根目录中about.php供应,即使请求不包括PHP扩展。

For example, the about page has a subdirectory named about that contains an index.php which is served when the request is http://www.example.com/about. I plan to change this so that about.php from the site's root directory is served even if the request doesn't include the php extension.

在我的开发服务器,问题是这些URL已经被改写,即使我没有一个的.htaccess 文件沿路径层次的任何地方。

On my development server, the problem is that the URLs are already being rewritten even though I don't have an .htaccess file anywhere along the path hierarchy.

Apache的配置是股市Ubuntu的配置,我怀疑它的一些独特的Ubuntu的,但我无法找到病因。

The Apache configuration is the stock Ubuntu configuration and I suspect that it's something unique to Ubuntu, but I can't find the cause.

下面是一些意见我做了:

Here are some observations I've made:

  • /etc/apache2/httpd.conf是空的,但配置是/etc/apache2/apache2.conf中这反过来包含取值配置文件从几其他目录。
  • 在任何地方有没有.htaccess文件在这个网站的层次结构。我检查了每一个目录开始,位于/ var / WWW
  • 在没有的.conf和.load文件/ etc / Apache2的任何引用改写除在/ etc / apache2的/ MODS可用。
  • 的rewrite.load文件
  • 在我设置了 LogWarning 指令进行调试。当我访问一个页面,而不PHP扩展,错误日志显示的URL与延伸和访问日志说明它不带扩展名和HTTP 200状态。本页面的供应正常。
  • 如果我加入的.htaccess 用适当的配置文件,我得到一个的.htaccess:无效的命令RewriteEngine叙述错误。 ... mod_rewrite的甚至没有被默认加载。
  • 如果启用了mod_rewrite通过连接到负载文件/ etc / apache2的/ MODS启用它正常工作,这是说完全一样,如果我不启用它。
  • /etc/apache2/httpd.conf is empty, but the configuration is in /etc/apache2/apache2.conf which in turn Includes config files from a few other directories.
  • There were no .htaccess files anywhere in the hierarchy of this site. I've checked every directory starting at /var/www
  • No .conf or .load files under /etc/apache2 have any reference to rewrite other than the rewrite.load file in /etc/apache2/mods-available.
  • I've set the LogWarning directive to debug. When I access a page without the .php extension, the error log shows the URL with the extension and the access log shows it without the extension and a HTTP 200 status. The page is served properly.
  • If I do add a .htaccess file with the appropriate configuration, I get an .htaccess: Invalid command 'RewriteEngine' error. ... mod_rewrite wasn't even loaded by default.
  • If I enable mod_rewrite by linking to the load file in /etc/apache2/mods-enabled it works as expected, which is to say exactly the same as if I didn't enable it.

access.log中显示:

access.log shows:

127.0.0.1 - - [16/Jan/2012:05:36:35 +0800] "GET /dev/ghodmode.com/h5bp/ HTTP/1.1" 200 3602 "http://alienware/dev/ghodmode.com/h5bp/experiments" "Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0"

而error.log中显示:

while error.log shows:

[Mon Jan 16 05:23:23 2012] [debug] mod_deflate.c(615): [client 127.0.0.1] Zlib: Compressed 5347 to 1876 : URL /dev/ghodmode.com/h5bp/experiments.php, referer: http://alienware/dev/ghodmode.com/h5bp/

如果我添加的.htaccess 文件:

[Mon Jan 16 05:34:33 2012] [alert] [client 127.0.0.1] /var/www/dev/ghodmode.com/h5bp/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration, referer: http://alienware/dev/ghodmode.com/h5bp/experiments

更新

感谢提供答案,我一直在读,我已经学到了一些东西。它的要点是,我使用现有的Ubuntu安装的Apache2和我并没有改变从默认的任何配置设置。因此,没有一个建议的原因被设置

Update

Thanks to answers provided, I've been reading and I've learned a few things. The gist of it is that I'm using a stock Ubuntu installation of Apache2 and I haven't changed any configuration settings from the default. So, none of the suggested causes are set.

当然有,我已经误解了某些文件的机会。这是我第一次读到一些选项。

Of course there is the chance that I've misunderstood some of the documentation. This is the first time I've read about some of these options.

多视图
多视图提供了这种情况的最好的解释,但是这需要一个类型映射或多视​​图选项设置为一个路径。我只有一个类型的地图(/etc/apache2/mods-enabled/mime.conf)的VAR和多视​​图选项仅适用于在/ usr /共享上设置/的Apache2 /图标。因此,这不可能吧。

Multiviews
Multiviews provides the best explanation of this scenario, but that requires a type map or MultiViews option set for a path. I only have one type map (/etc/apache2/mods-enabled/mime.conf) for 'var' and the MultiViews option is only set for /usr/share/apache2/icons. So, this couldn't be it.

重定向和放大器; RedirectMatch
重定向和放大器; RedirectMatch 将提供一个很好的解释了这种行为,但它需要一个指令,每一个重定向。我没有任何这些设置,如果它存在的I型服务相关的php文件的任何路径。此外,如果这是原因,我认为access.log中会产生3xx状态,而不是200,如果它是一个重定向。

Redirect & RedirectMatch
Redirect & RedirectMatch would provide a good explanation for this behavior, but it requires a directive for each redirection. I don't have any of these set and any path that I type serves the related php file if it exists. Also, if this was the cause, I think that the access.log would generate a 3xx status instead of 200 if it was a redirect.

别名和放大器; Alias​​Match
别名和放大器; Alias​​Match ,就像重定向和放大器; RedirectMatch,需要一个指令,每个资源进行设置。我只对/图标/.

Alias & AliasMatch
Alias & AliasMatch, like Redirect & RedirectMatch, requires a directive to be set for each resource. I only have an alias set for /icons/.

FallbackResource
FallbackResource 确定一个单一的资源来服务时所请求的资源ISN牛逼present。在我的情况下,如果请求的资源是不是present它提供通过追加名'.php'的请求结束找到资源。我也双重检查,有没有设置指令FallbackResource

FallbackResource
FallbackResource identifies a single resource to serve when the requested resource isn't present. In my case, when the requested resource isn't present it serves the resource found by appending '.php' to the end of the request. I also double-checked and there are no FallbackResource directives set.

下面是我用它来确认有没有设置特定选项的任何地方命令的例子:

Here's an example of the command I use to confirm that there a particular option isn't set anywhere:

find /etc/apache2 -name "*.conf" -exec grep -li "FallbackResource" {} \;

更新#2:

有我在寻找的MultiViews选项一个洞。我只是在寻找一个.conf文件或.load扩展名的文件,但有些配置文件不具有扩展名的。该MultiViews选项是默认的站点配置文件中设置的/ etc / apache2的/站点启用/ 000默认。

Update #2:

There was a hole in my search for the MultiViews option. I was only looking for files with a .conf or .load extension, but some of the configuration files don't have an extension at all. The MultiViews option is set by the default site configuration file /etc/apache2/sites-enabled/000-default.

感谢@zneak为先提供答案,尽管他在一个注释。而得益于@regilero谁间接地向我展示了我失踪了使用不同的语法的grep 从语法,我已经习惯了。

Thanks to @zneak for providing the answer first, although he did it in a comment. And thanks to @regilero who indirectly showed me what I was missing by using a different syntax for grep from the syntax I'm used to.

推荐答案

你叫什么重写可以通过很多其他的指令来完成:

What you call a rewrite can be done by a lot of others instructions:

论文配置的东西通常不是在.htaccess文件默认情况下,因为.htaccess文件仅仅是一个坏事放缓Apache和允许用户添加一些其他规则比VirtualHosts定义的。最有用的配置的东西是的/ etc / apache2的/站点启用的/ etc / apaches2 / MOD-enableds / /etc/apache2/conf.d /

Theses configuration things are usually not in .htaccess files by default, as .htaccess files is just a bad thing slowing down apache and allowing user to add some other rules than the one defined in VirtualHosts. Most usefull configuration stuff is in /etc/apache2/sites-enabled, /etc/apaches2/mod-enableds/ and /etc/apache2/conf.d/.

现在最奇怪的是选项多视图制作的grep -R多视图的/ etc / apache2的/ * 。此选项将映射任何调用 http://www.example.com/foo/bar 以富/ bar.php或富/一个bar.html如果论文目录存在于DocumentRoot的,如果论文文件存在(在所有可用扩展尝试)。

Now the strangest one is Option Multiviews make a grep -R MultiViews /etc/apache2/*. This option will map any call to http://www.example.com/foo/bar to foo/bar.php or foo/bar.html if theses directories exists in the DocumentRoot and if theses files exists (trying on all available extensions).

这篇关于Apache的重写没有mod_rewrite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆