Can anyone help me please with .htaccess?
I have a folder system on my site:
user
- index.php
- profile.php
- login.php
- other pages.php
page
contact.php
products.php
index.php
When someone comes to my website example.com it shows the index.php page. I use .htaccess to have clean URL's.
example.com/contact must include /page/contact.php into index.php.
example.com/user/username/profile must include /user/profile.php into user/index.php.
example.com/products/spinningbike include product.php into index.php and shows the details of product spinningbike.
This is my .htaccess file:
RewriteEngine On
RewriteRule ^login /user/login.php [L]
RewriteRule ^user/(\w+)/?$ /user/index.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1
I always get these php errors in my log files:
PHP Warning: include(): Failed opening 'page/user.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/example.com/public_html/index.php on line 115, referer: http://www.example.com/user/wim/profile PHP Warning: include(page/user.php): failed to open stream: No such file or directory in /home/example.com/public_html/index.php on line 115, referer: http://www.example.com/user/wim/profile
I think the [L] is not working properly.
index.php, your script tries to include the filepage/user.phpwhich does not exist. - ᴄʀᴏᴢᴇᴛ.htaccessshould stop at the second rewriterule, so my last rewrite rule should not be excecuted. That's why I get that php error. - wimdemohttp://example.com/user/username/as you have "profile" at the end of the url, the last rule is used - ᴄʀᴏᴢᴇᴛ