Page 1 of 1

URLS and .htaccess

Posted: Thu Sep 03, 2009 9:37 pm
by visionary_tomato
Hi there PHP folk!

I'm an aspiring web developer and I have a question regarding urls and .htaccess. I'm working as a teacher at the moment but I want to get into development.

Here's the deal:
I want my hyperlinks to work like this:- href="domain.poo/page/"

but I want my server to see this:- "domain.poo/index.php?page=page"

And I want the URL to display the address bar like this (clients to see this):- "domain.poo/page/"

So correct me if I'm wrong (and please try to spell it out for me, I'm quite slow at times) but here's my current understanding:
- For optimising SEO: having URLS like 'domain.poo/page/?opt=value&etc=etc' is generally better!
- But if I'm picking up everything through my index page, it needs to be seeing 'index.php?page=page' to my server or my server needs to change it to this before my php scripts look at it... right?

As far as I understand, .htaccess can easily change a 'domain.com/index.php?page=page' to display as 'domain.com/page/'... but I for some reason REALLY want my hrefs to use the same formatting as that which the address bar displays...... so is it even possible to go from '.poo/page/' to '.poo/index.php?p=page' and then back to '.poo/page' for the users display and is there actually a SEO advantage to my preference or am I imagining things? Lol..

Thanks a heap and yes I realise this is probably the wrong forum for this question, I just have no idea which one it should go in >_<

- Lump

Re: URLS and .htaccess

Posted: Thu Sep 03, 2009 10:24 pm
by visionary_tomato
This seems like a dumb solution:

Each 'domain.poo/page/' folder has an index.php that does nothing but set the Header to 'index.php?page=page' and then my .htaccess changes the display url to 'domain.poo/page/'

Lol, that's so wrong, there must be something better than redirecting back to my index for every page change...

Re: URLS and .htaccess

Posted: Thu Sep 03, 2009 10:36 pm
by John Cartwright
Moved to Installation and Configuration.

Re: URLS and .htaccess

Posted: Thu Sep 03, 2009 10:44 pm
by visionary_tomato
thanks john

Re: URLS and .htaccess

Posted: Sat Sep 05, 2009 1:08 am
by visionary_tomato
So I was being dumb and misunderstood the implementation of .htaccess.

I can do what I aimed to achieve but a new problem has occured:

Code: Select all

RewriteRule ^([^.*]+)/$ /TestProject/index.php?page=$1
Is fine and dandy

But if I try to implement anything like:

Code: Select all

RewriteRule ^([^.*]+)/(^.*)?$   /TestProject/index.php?page=$1&$2
It just doesn't provide the extra functionality...

I can't add to my $_GET array through the URL..
I just want this to work:

Code: Select all

<a href="/TestProject/page/?key=value&key2=value2">Page with GET array</a>
What am I doing wrong here?

Re: URLS and .htaccess

Posted: Sat Sep 05, 2009 7:15 am
by visionary_tomato

Code: Select all

RewriteRule ^([A-Za-z0-9_-]+)/([^/.]+)*$    /TOMS/TestProject/index.php?page=$1&$2  [NC,L]
This works for urls '/TOMS/TestProject/page/key=value&key2=value2' etc but not for '/TOMS/TestProject/page/?key=value&key2=value2' I'm not quite sure how important the question mark is :o