.htaccess working locally, but not on 1and1 server - apache

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

Related

How can I hide file extensions in the URL of my site with Apache?

Before anyone says this is a duplicate - I tried all other similar questions without any successful results.
I use apache.
I am trying to hide file extensions in the URL. For example, index.php would show as index in the URL.
So what I did:
1) I created a .htaccess file, pasted this into it:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [NC]
RewriteCond %{REQUEST_URI} ^/(.+?)/$
RewriteCond %{DOCUMENT_ROOT}/%1\.html -f
RewriteRule ^ /%1.html [L]
RewriteCond %{REQUEST_URI} ^/(.+?)/$
RewriteCond %{DOCUMENT_ROOT}/%1\.php -f
RewriteRule ^ /%1.php [L]
2) Uploaded .htacccess to www/html folder
3) Restarted apache
4) Ran sudo a2enmod rewrite
5) Restarted apache again
6) Went to /etc/apache2/sites-enabled/000-default.conf and pasted this in the <VirtualHost *:80> tab:
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
7) restarted apache
And... file extensions still show on my website. This is my first time playing around with .htaccess so can someone please explain what I am doing wrong and the steps I should take to do this correctly?
Best thing to do is break down the rules and apply them one at a time.
Remove everything in .htaccess and addthe below
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Now see if files with .php extension resolve correctly.
Then add the .html rule. It is exactly the same just change the extension.

Cannot enable mode rewrite

I want to use mod_rewrite with Wampserver to remove "/index.php/" from addressbar. This code is suggested with Codeigniter Framework:
RewriteEngine on
#RewriteBase /
RewriteCond $1 !^(index\.php|img|table-images|robots\.txt|css|fonts|js|uploads|dbg-wizard\.php)
RewriteRule ^(.*)$ index.php/$1 [L]
This should change this url:
mysite.local/contact_us
to this:
mysite.local/index.php/contact_us
This works with XAMPP but with Wampserver first URL generates Error 404!
I enabled mod_rewrite with Apache and there is no errors in error log.
Update:
I added .blabla in .htacess but nothing happened! It means that Apache does not read .htaccess! Why?
I added AllowOverride All to httpd-vhosts.conf.
Apache did not execute .htaccess and enabling AllowOverride in httpd.conf is not enough.
This is my httpd-vhosts.conf file:
<Directory E:\mysite\www>
Options Indexes FollowSymLinks Includes ExecCGI
#Order Deny,Allow
#Allow from all
AllowOverride All
Require all granted
</Directory>
To check that mode rewrite is working or not try these steps:
Make a folder in your root directory called htaccess_test
Create a .htaccess file, and put these code into this and save it.
options +FollowSymLinks RewriteEngine On
RewriteBase /htaccess_test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ user.php?u=$1
Create one more file called user.php and put these code into
this and save it.
<?php
if(isset($_GET['u'])){
echo $_GET['u'];
}
Now go to browser type http://localhost/htaccess_test/put_some_value_here.
If that is working than the problem is not in your apache setting.
Make sure you are editing the right .htaccess file. The .htaccess file you need to edit is in your projects' root folder, not in application or any other folder. And put these code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /root_directory_of_your_project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

500 Internal Server Error on Xampp's Virtual Host

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]

htaccess redirection wont work on local server

i installed apache server on my windows computer but i cant make this htaccess work:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*?)/?$ index.php?s=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ index\.php\?s=([^\s]*)
RewriteRule ^/?(.*?)/?$ %1?%2%3 [L,R=301]
This htaccess works perfectly on my paid server (linux) and its supposed to convert queries into paths. Could any misconfiguration be preventing it from working?
Did you check you Apache config file? Most likely the problem is your settings.
If you are using Apache 2.3.9 or greater the AllowOverride setting is None by default. Check you httpd.conf or apache2.conf file and look in the <directory> section and make sure it says AllowOverride All instead of AllowOverride None.

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.