Page 1 of 1

.htaccess BUT keep index.php

Posted: Thu Dec 22, 2011 8:05 pm
by EcazS
This is mainly an htaccess problem I guess but it has to do with PHP for now!
So basically I want prettier URLs but I want to keep index.php in the URL! So normally you would have domain.com/home or domain.com/about BUT I want it like domain.com/index.php/home.

I'm getting info from a database with the old fashioned $_GET, mine is $_GET["p"].
So my current .htaccess file looks like this,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ index.php?p=$1 [NC]
But this doesn't keep index.php in the URL so if you guys have any idea on how to achieve this then I would greatly appreciate you telling me :P

Re: .htaccess BUT keep index.php

Posted: Thu Dec 22, 2011 9:25 pm
by jacek
You could jutt include the index.php part in the match line ?
RewriteRule ^index.php/(.*)$ index.php?p=$1 [NC]
Something like that ?

Re: .htaccess BUT keep index.php

Posted: Thu Dec 22, 2011 10:08 pm
by EcazS
I tried that at first but it didn't work so I removed this,
RewriteRule .* - [L]
line because it looked suspicious and now it's working.
Problem is, it breaks the folder structure so it doesn't link the CSS file :/

Re: .htaccess BUT keep index.php

Posted: Thu Dec 22, 2011 11:59 pm
by bowersbros
Do direct links to CSS instead of relative?

Re: .htaccess BUT keep index.php

Posted: Fri Dec 23, 2011 12:28 am
by EcazS
bowersbros wrote:Do direct links to CSS instead of relative?
Then I have to somehow force users into doing that :/ Which is tricky.
And images would then also have to be directly linked outside of the css :/

Re: .htaccess BUT keep index.php

Posted: Fri Dec 23, 2011 4:37 pm
by jacek
It should not break the css links if you use a / at the start of your href. for example, imaging you are at http://something.com/index.php/page and you have
<link rel="stylesheet" type="text/css" href="ext/css/main.css" />
That will try to request http://something.com/index.php/page/ext/css/main.css which may be wrong.

but if you use
<link rel="stylesheet" type="text/css" href="/ext/css/main.css" />
it will try to request http://something.com/ext/css/main.css which is probably right :)

/ means root.