500 Internal Server Error on Xampp's Virtual Host - apache

I'm using Xampp and I have a lot of web projects in my computer, so I decided to create a Virtual Host, but I'm getting the following error in the log when I use htaccess rewriterules to make some friendly URLs:
AH00124: 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.
I've tried a lot of things posted here, but nothing worked... Can you guys help me?
My Virtual Host:
<VirtualHost myproject.com:80>
ServerName myproject.com
ServerAlias www.myproject.com
DocumentRoot "D:/xampp/www/myproject"
<Directory "D:/xampp/www/myproject">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
My .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^404/$ /404.html [L]
RewriteRule ^404$ /404.html [L]
RewriteRule ^([^/]*)/$ /index.php?p=$1 [L]
RewriteRule ^([^/]*)$ /index.php?p=$1 [L]
Thank you very much :D

These are very simple rules, but it should work fine for your case, and it should help you start building some more complex rewrite rules.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(404|404\/)$ /404.html [L]
# Make sure to avoid loops.
# Ignore rewrite rules for the files and directories that
# exist (such as index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?p=$1 [L]

Related

Redirect if specific URL is given with htaccess

I have a very straightforward url friendly htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(\w+)/?$ index.php?id=$1
So domain.com/something is mapped to domain.com/index.php?id=something.
Every URL can have an additional parameter, so for example domain.com/something can be in the form of domain.com/something?custom_value
Now I need to address this particular situation: If a particular ID is matched, then a custom value must be forced. So, if I go to domain.com/somethingelse I want to be redirected to domain.com/somethingelse?custom_value
I've tried different rules with no luck. This was my last attempt but I get a message that the server is making a rediretion that will never be completed.
RedirectMatch 301 ^/(somethingelse)/?$ /somethingelse?custom_value
Another attempt was this, resulting in a 500 Internal Server Error
RedirectMatch 301 ^/(somethingelse)/?$ somethingelse?custom_value
complete htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RedirectMatch 301 ^/(somethingelse)/?$ somethingelse?custom_value
RewriteRule ^(\w+)/?$ index.php?id=$1
EDIT 1:
Well, apparently this rule works (not always) on local machine, but no online server
RedirectMatch 301 ^somethingelse$ somethingelse?custom_value
EDIT 2:
I've also tried (also works on local machine, but no online server)
RewriteRule ^/somethingelse$ /somethingelse?test [L,R=301]
EDIT 3
These are my virtualhosts:
local virtual host
<VirtualHost vhostname>
DocumentRoot /var/www/path/to/project
<Directory /var/www/path/to/project>
AllowOverride All
</Directory>
</VirtualHost>
server virtual host
<VirtualHost *:80>
ServerName subdomain.domain.com
DocumentRoot /var/www/path/to/project
<Directory /var/www/path/to/project
AllowOverride All
</Directory>
</VirtualHost>
You may use these rules in your site root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^somethingelse/?$ %{REQUEST_URI}?custom_value [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)/?$ index.php?id=$1 [L,QSA]
Make sure to test this in a new browser or test it after completely clearing your browser cache.

Can't get Anchor CMS rewriting to work

I'm currently attempting to install Anchor CMS on my Apache server.
I have successfully deployed it to the server. That is, when I go to www.domain.com, I am greeted with the default-themed front page and a test post :)
However, if I try to click the post, or go to the admin area, I get an error such as:
Not Found: The requested URL /posts/hello-world was not found on this server.
However, if I follow the (in this case) post link using a direct link, such as:
www.domain.com/index.php/posts/hello-world
It works completely fine. So, it appears to be a problem with the rewriting.
I found another problem on Stackoverflow exactly like mine, located here
Unfortunately, I did the same steps and nothing works. Just to recap, this is how my VirtualHost looks:
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/domain.com/public_html
<Directory /var/www/domain.com/public_html>
AllowOverride All
Require all granted
</Dictory>
</VirtualHost>
And this is how my Anchor CMS config.app file looks:
return array(
'url' => '/',
'index' => '',
...(rest of the data here)...
As the documentation states to use an empty index in this default case.
My .htaccess currently looks like this:
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
And it is located in the document root "public_html"
Sadly, even with these things configured, I still get the "Not Found" errors. I don't really know where to go from here :(
EDIT
Options -indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^ http://google.com [R,L]
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
I tried to put in a general rewrite to the .htaccess file, and it seems like it's not being executed:
It appears that the mod-rewrite is not being loaded.
See your server configuration file (httpd.conf). There should be a statement as follows:
LoadModule rewrite_module modules/mod_rewrite.so
If the line starts with #, remove the # character. You can also use the command:
a2enmod rewrite
Also, try to shift your Rewrites outside of the IfModule block.
Options -indexes
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [L]

Silex rewrite, one.com

I am using this apache rewrite, when i am on my local machine.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
But after i uploaded it, to my host i get server error. They told me they dont support Options, but i can't get it working without that.
I am trying to route my Silex installation, so its /web/stats/ instead of web/index.php/stats.
I found this example for Codeigniter http://www.chrishjorth.com/blog/one-com-codeigniter-htaccess-rewrite-rules/
Anyone know how to make it work with Silex?
Same problem at some hosters. If your server has installed Apache >= 2.2.16 you can use the FallbackResource command:
FallbackResource /index.php
in your .htaccess instead of
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
See also Apache’s fallbackresource: your new .htaccess command for more information.

.htaccess working locally, but not on 1and1 server

I uploaded the current .htaccess file to a 1and1 server (actually 1und1.de, but I guess it's the same) and I'm geting a 500 Internal Server Error.
Options -MultiViews
RewriteEngine On
RewriteBase /lammkontor
RewriteRule ^categories/([^/\.]+)/?$ index.php?url=category.php&cat_url=$1 [L]
RewriteRule ^categories/([^/\.]+)/([^/\.]+)/?$ index.php?url=product.php&cat_url=$1&prod_url=$2 [L]
RewriteRule ^categories/([^/\.]+)/([^/\.]+)/recipes?$ index.php?url=recipes.php&cat_url=$1&prod_url=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+\.php)/?$ index.php?url=$1 [QSA]
This .htaccess works perfectly on my local MAMP server.
When I test the CGI-Monitor in the control-center with an example file I get
- cgi: File not present or has invalid modes
(no output)
The only file working now is index.php
Thanks for your help!
Actually I solved my problem adding a slash to the beginning of every Rewrite Rule, like:
RewriteRule ^(.+\.php)/?$ /index.php?url=$1 [QSA]
instead of
RewriteRule ^(.+\.php)/?$ index.php?url=$1 [QSA]
Thanks!
By default apache's htaccess rights are off or limited depending on your host.
I suspect its your Options -MultiViews causing the error.
Check your httpd.conf and check that MultiViews is allowed like below.
<Directory />
Options FollowSymLinks
AllowOverride Indexes Options=All,MultiViews
Order deny,allow
Deny from all
</Directory>
Just put a slash before the url. eg /index.php instead of index.php at the end of the rule

Infinite loop with mod_rewrite and vhost_alias

I made myself a dynamic vhost file for all directories in /home/lukasz/websites
<VirtualHost *:80>
ServerName vm01.dev
ServerAlias *.vm01.dev
SetEnv APPLICATION_ENV "lukasz"
VirtualDocumentRoot /home/lukasz/websites/%1/public
<directory /home/lukasz/websites/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</directory>
</VirtualHost>
It works well until very simple rule from mod_rewrite comes to play. If I add following code to the .htacesss
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
The apache server will be unable to respond. It will go into an infinite loop and will break out from the execution after 10 redirects. This problem is tightly related to VirtualDocumentRoot I'm using. How should I modify my config to keep it dynamic and stop it breaking with about htaccess?
I'm guessing you want to make index.php the default page, when the requested resource doesn't exist, you didn't say.
If this is the case then adding an ErrorDocument entry to your virtualHost will suffice e.g.
ErrorDocument 404 /index.php
If you are going to use mod_rewrite, it's far more efficient to place the rules in the Virtualhost definition than in a .htaccess file. As the httpd.conf is read once at start-up and all rule compiled, as opposed to the .htaccess file being read and all rules parsed for each request. Anyway the following should stop the loop:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]
Assuming you have an: /index.php
FYI: The Apache mod_rewrite documentation is worth a read if your unclear as to what the above rules do, or if you want something a little more abstract consider the following post.