Magento .htaccess file RewriteBase setting? - apache

I've resolved a problem I got when I set up a staging environment for my existing live Magento store. But I don't understand why it worked & why I didn't have the problem on my live site.
The was the error I was getting, whenever I tried to navigate off my sites staging homepage I got a 500 Internal Server Error.
In the error logs I got this:
[Tue Dec 17 01:12:52 2013] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Tue Dec 17 12:56:17 2013] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://localhost.mysite.com/
With a little research online, I solved it by changing the .htaccess file RewriteBase setting to RewriteBase /. On my live site this setting is commented out as #RewriteBase /magento/.
Why is this setting only needed in my staging environment?
Should it be on the live environment too or should it be avoided
entirely?
I'm running the site locally on an Apache2 server on an Ubuntu
machine, maybe it has something to do with my local server set up?

Why is this setting only needed in my staging environment?
Probably because your staging environment is in a directory called /magento/ inside your document root. When you have checks like:
RewriteCond %{REQUEST_FILENAME} !-f
and the base is wrong, the check to see if a file exists fails. The base is used to append to the beginning of relative URL-paths. So if your files are in /magento/ then without the proper base, your checks will fail and your rules will loop indefinitely (or until the internal recursion limit is reached). On your production environment, the files are probably in your document root, so the base isn't completely necessary, since the rules are in the same directory as the files you are rewriting to.
As for the other 2 questions, can't answer without looking at all your rules and all of your setup.

Related

Why isn't apache serving the page? mod_rewrite seems to have found the right file

The project I'm working on has a fairly long & complicated list of RewriteRules, separated into 2 .htaccess files for legacy reasons. I'm putting the app into a Docker container to make it easier to on-board new developers, but the Ubuntu/Apache combo is choking on the RewriteRules and giving me an HTTP 500.
Docker image: php:5.6-Apache
Apache Version: 2.4
I boosted the logging to trace4 and it appears to figure out the right file - here's the last line of the mod_rewrite debug output
[Thu Mar 16 09:08:15.459987 2017] [rewrite:trace1] [pid 17] mod_rewrite.c(475): [client 192.168.99.1:63990] 192.168.99.1 - - [rs.dev/sid#7f51cf6fece0][rid#7f51cf61c8f8/initial/redir#3] [perdir /var/www/appname/public_html/production/] pass through /var/www/appname/public_html/production/login.php
The file '/var/www/appname/public_html/production/login.php' exists, and is the file that should be loaded. However, the response is sent as a 500, (and the page doesn't load). I'm using the /login URL here as an example, but it happens on all URLs.
This works on the localhost of a Mac running macOS, and it works in cPanel servers, I just can't seem to get it running in the Ubuntu base that Docker's providing me.
Does anyone know why Apache would use mod_rewrite and appear to identify the correct file, but then not use the file?
For reference, the entire log output from the request is on pastebin.
It turns out that my problem wasn't in the Rewriting at all, I had forgotten to create a file that PHP was trying to require, so it was throwing a PHP error. However, the way the logs were configured, the error was disappearing into the ether, (or into a log I haven't found yet).
Let that be a lesson - even if you're absolutely sure where the error is, you might still be wrong!

500 Internal Server Error when adding .htaccess file on root of MAMP

I'm getting a 500 Internal Server Error when I add an .htaccess file to the root of my site on MAMP. I have a virtual host set up, so the site is accessable through site.dev and my files live in /Users/Dan/Websites/site. There isn't any .htaccess files above the my current directory. At first, I thought it was something going on inside of my file, but I removed everything except for a commented line and the error is still there. When I have a blank file, the error goes away.
Update: Here's the error log
[Mon Apr 01 11:17:18 2013] [alert] [client 127.0.0.1] /Users/Dan/Websites/site/.htaccess: Invalid command '\xff\xfe#', perhaps misspelled or defined by a module not included in the server configuration
Any ideas?
\xff\xfe is the byte-order marker (BOM) for UTF-16. There's nothing wrong with that but Apache doesn't seem to support BOMs at all. So you'll need to save your .htaccess file with a different encoding, either a single-byte one or UTF-8 without BOM.

Help Needed With (I thought) Basic mod_rewrite Setup

I run my own server at home. I am attempting to do a mod_rewrite but I cannot seem to get it to work correctly.
Say my url is "http://www.site.com/". I have a user set up, whose public_html directory is serving pages; let's say that url is "http://www.site.com/~myUser/theDirectory/". What I am trying to do is set it so that when you type in "http://www.site.com/theDirectory/" it will actually serve the pages out of "http://www.site.com/~myUser/theDirectory/", but look like its coming from "http://www.site.com/theDirectory/". I edited my /etc/apche2/sites-enabled/default file and added these lines:
RewriteEngine On
RewriteRule ^theDirectory/$ /home/myUser/public_html/~myUser/theDirectory/
I also tried various versions of the rule:
RewriteRule ^/theDirectory/$ /home/myUser/public_html/theDirectory/
RewriteRule ^/var/www/html/theDirectory/$ /home/myUser/public_html/theDirectory/
I also made sure that the rewrite module was enabled. At first, I was getting this error:
[Fri Jun 17 18:11:35 2011] [error] [client xxx.xxx.xxx.xxx] File does not exist: /var/www/theDirectory
So I created that file, and now I am getting this error:
[Fri Jun 17 23:15:45 2011] [error] [client xxx.xxx.xxx.xxx] Directory index forbidden by Options directive: /var/www/theDirectory/
So, I'm not really sure where to go from here. Any and all advice will be appreciated. Thanks for taking the time to read.
Have a great day :-)
Add the following to your virtual host configuration:
RewriteEngine on
RewriteRule ^/theDirectory(/.*)$ /home/myUser/public_html/theDirectory$1 [L]

Apache and Internal Server error and internal redirects on WordPress install

I am unable to do WordPress installations automatically on my local Apache for the past 4 weeks. The normal process on another machine goes standard - copy the WP install, run and the install script is executed. What I see here is either blank page, or Internal Server Error.
Even if I do correct manually my wp-config.php file with the settings and install, I receive the same error again. The last WP versions are distributed with no .htaccess so I expect no .htaccess to be required on each install for my local server.
Here there are my httpd.conf settings for the directory:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
AllowOverride All
</Directory>
mod_rewrite is loaded here.
I was suspicious about my /etc/hosts as well, but we have the following:
127.0.0.1 localhost localhost.localdomain
I had a look in my php.ini file (PHP is 5.3.3), no specific problems. However, my error log from apache states the following:
[error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Any ideas?
It sounds like there is either a rewrite rule causing an endless rewrite loop or some other kind of alias loop in your config. Without seeing the rest of your apache config I wouldn't be able to tell for sure.

mod_rewrite generating errors in log

On my site I have mod_rewrite rules to make the URLs more search engine friendly, and it all works fine on the frontend, but I'm getting errors in the error log like this
[Thu Jan 22 22:51:36 2009] [error] [client {IP ADDRESS HERE}] File does not exist: /{some rewritten directory}
The rules I'm using are rather simple, along the lines of
RewriteRule ^pages/(.*)_(.*).html$ page.php?id=$2
Is there a way to avoid these errors?
MultiViews could cause this. If it is enabled, Apache tries to find a file similar to the requested URI before passing the request along to mod_rewrite. So try to disable it:
Options -MultiViews
I don't think those errors have anything to do with mod_rewrite, they're just saying that a file doesn't exist. Plain old 404 errors.
Incidentally, shouldn't rewrite patterns normally start with a slash? Like so:
RewriteRule ^/pages/(.*)_(.*).html$ /page.php?id=$2