Reputation: 376
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?
Upvotes: 2
Views: 241
Reputation: 376
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.
Upvotes: 0
Reputation: 11615
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
Upvotes: 1