2

I made a website that I run locally. I configured a my host file and virtual host:

Adress: website.dev
DocumentRoot:  /www/website/public_html

I can access the website correctly.

In the public_html folder are the following files:

index.php
.htaccess

I tried to configure an .htaccess file, but I am not very experienced with that so maybe I did something wrong.

The idea is that every request like 'website.dev/users' or 'website.dev/login' is processed by the index file so I can handle the given URL. (I think that the URL: website.dev doesn't need a rewrite, because it directly leads to the index.php because it is the documentRoot)

This works fine but I noticed, when I use a rewriteRule in the .htacces file that my pages got opened called multiple times.

This is my .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f


RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php  [NC,L]

When I comment out all the rewriteRule lines, and go to: website.dev, I see that my pages only got called once. What in the .htaccess file can cause the double page calls?

5
  • Is Address really misspelled in your virtual host file? You have Adress instead of Address. You also had htacces instead of htaccess several places. Commented Nov 9, 2012 at 22:56
  • Thanks for your comment, i'm sorry for the misspells I had to write this down quickly. But i can assure you that there are no misspells in the virtualhost file. Commented Nov 10, 2012 at 9:05
  • How do u know your pages are being called twice? Commented Nov 23, 2012 at 16:09
  • Sorry I did not answered earlier but i haven't logged in on stackoverflow for a while, but i remember the solution, I found the problem by looking into the apache log files, so i noticed the webserver (wamp) looked for a .ico file (wamp logo) to show in the browsers addresbar, but in my project this file did not exists, that created a 404 and so the the index file was called again, i created the needed ico file in my project folder and everything worked like a charm. Commented Jun 26, 2013 at 9:27
  • @JelteVerbree Welcome back, you could add that (important part) as an answer and accept it.
    – HamZa
    Commented Jun 26, 2013 at 9:35

2 Answers 2

1

Some of the conditions aren't required.

you're testing:

is the file size > 0 OR is a symbolic link, OR is directory OR is a regular file.

I've got the below which rewrites /users/id to: index.php?url=users/id

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule    !\.(jpg|css|js|gif|png)$    public/    [L]
RewriteRule !\.(jpg|css|js|gif|png)$ public/index.php?url=$1
0

Solution:

I found the problem by looking into the apache log files, so i noticed the webserver (wamp) looked for a .ico file (wamp logo) to show in the browsers addresbar, but in my project this file did not exists, that created a 404 and so the the index file was called again, i created the needed ico file in my project folder and everything worked like a charm.

Not the answer you're looking for? Browse other questions tagged or ask your own question.