When I request my website, I'm trying to add trailing slash to the URL and then pass it to index.php as parameter using mod_rewrite.
My .htaccess file looks like this:
RewriteEngine On
#Add trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [R]
#Pass to index.php
RewriteRule ^(.*)/$ index.php?p=$1
And in my index.php file just outputs the parameter:
<?php echo $_GET["p"]; ?>
But when I type to the adress bar anything except http://mydomain.com/, for example http://mydomain.com/contact, the php always outputs http://mydomain.com/index.php
. So http://mydomain.com/index.php
was somehow passed as the parameter instead of the requested page such as contact
, but I don't know why...
Also, when I edit
RewriteRule ^(.*)/$ index.php?p=$1
to
RewriteRule ^(.*)/$ /index.php?p=$1
and I type URL e.g. mydomain.com/contact
Apache gives me 302 Found and a link to where it was moved, but it links to the same page...
Any Ideas?
Thanks.