.htaccess BUT keep index.php

Ask about a PHP problem here.
Post Reply
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

.htaccess BUT keep index.php

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: .htaccess BUT keep index.php

Post 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 ?
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: .htaccess BUT keep index.php

Post 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 :/
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: .htaccess BUT keep index.php

Post by bowersbros »

Do direct links to CSS instead of relative?
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: .htaccess BUT keep index.php

Post 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 :/
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: .htaccess BUT keep index.php

Post 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.
Image
Post Reply