How can Apache rewrite URLs without including or mod_rewrite setting?
I am working on a website redesign from my development server. I used the directory structure for the sections of the site, but I am considering switching to rewriting URLs and placing related files in the root of the site.
For example, on the about page, there is a subdirectory called about that contains 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 root directory of the site is served, even if the request does not include the php extension.
On my development server, the problem is that the URLs are already rewritten, although I don't have a .htaccess file anywhere in the path hierarchy.
Apache configuration is the basic configuration of Ubuntu, and I suspect that it is unique to Ubuntu, but I can not find the reason.
Here are some comments I made:
- /etc/apache2/httpd.conf is empty, but the configuration is in the file / etc / apache 2 / apache2.conf, which, in turn,
Include configures files from several other directories. - There were no .htaccess files in the hierarchy of this site. I checked every directory starting with / var / www
- In .conf or .load files under / etc / apache 2 there is a link to rewrite, except for the rewrite.load file in / etc / apache 2 / mods-available.
- I set the
LogWarning directive for debugging. When I access a page without the .php extension, the URL with the extension is displayed in the error log, and the access log shows it without the extension and HTTP-200 status. The page is done correctly. - If I add a
.htaccess file with the appropriate configuration, I get a .htaccess: Invalid command 'RewriteEngine' error .htaccess: Invalid command 'RewriteEngine' .... mod_rewrite was not even loaded by default. - If I enable mod_rewrite by linking to the download file in / etc / apache 2 / mods-enabled, it works as expected, that is, exactly the same as if I hadn't included it.
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"
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/
If I add a .htaccess file:
[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
Update
Thanks to the answers provided, I read and I learned something. Its essence is that I use the Ubuntu installation to install Apache2, and I have not changed any default configuration settings. Thus, none of the proposed reasons is given.
Of course, there is a chance that I misunderstood part of the documentation. This is the first time I have read some of these options.
Multiviews
Multiviews gives a better explanation of this scenario, but it requires a type map or MultiViews given for the path. I have only one map of type (/etc/apache2/mods-enabled/mime.conf) for 'var', and the MultiViews option is set only for / usr / share / apache 2 / icons. So it could not be.
Redirect and RedirectMatch
Redirect and RedirectMatch provide a good explanation for this behavior, but a directive is required for each redirect. I don't have any of these sets, and any path I type serves the linked php file, if one exists. Also, if that was the reason, I think access.log would generate 3xx status instead of 200 if it was a redirect.
Alias ββand AliasMatch
Alias ββand AliasMatch , such as Redirect and RedirectMatch, require a directive for each resource. I only have an alias for / icons /.
Fallbackresource
FallbackResource defines the only resource that will be used when the requested resource is missing. In my case, when the requested resource is missing, it serves the resource found by adding ".php" to the end of the request. I also double checked that there are no FallbackResource directives.
Here is an example of a command that I use to confirm that a particular parameter is not set anywhere:
find /etc/apache2 -name "*.conf" -exec grep -li "FallbackResource" {} \;
Update # 2:
A hole appeared in my search for the MultiViews option. I searched for files with the extension .conf or .load, but some configuration files do not have an extension at all. The MultiViews parameter is set by default to the default site configuration file / etc / apache 2 / sites-enabled / 000.
Thanks to @zneak for providing the answer first, although he did this in a comment. And thanks to @regilero, which indirectly showed me what I was missing, using a different syntax for grep from the syntax I'm used to.