Forum Moderators: coopster

Message Too Old, No Replies

Spider friendly URL not working on index.php

using the parameter on index.php

         

kenchix1

10:26 am on Jul 21, 2005 (gmt 0)

10+ Year Member



I write a small script that uses the path_info to replace the query.

I tested the script using a different filename (listit.php) together with the parameter

wwWebmasterWorldebsite.dom/listit.php/mysingleparameter

this works ok.

but when I renamed the listit.php to index.php, it doesn't work anymore when I use

wwWebmasterWorldebsite.dom/mysingleparameter

but if I use

wwWebmasterWorldebsite.dom/index.php/mysingleparameter

it was ok.

is there a solution for this?
I'd like the URL to be as short as possible so I want to eliminate the need to add index.php or filename.php

Thanks in advance.

ergophobe

4:33 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In the different cases, your path is a different length, so that will mess up anything that is using pathinfo(). The key question is: Once you've used pathinfo() to break out your path into its elements, what are you doing with that info? Are you parsing it using explode()? Are you including it using include() or require()?

In the case of
wwWebmasterWorldebsite.dom/mysingleparameter

the dirname is wwWebmasterWorldebsite.dom
the basname is mysingleparameter

but in the case of

wwWebmasterWorldebsite.dom/index.php/mysingleparameter

the basename is the same, but the dirname is now
wwWebmasterWorldebsite.dom/index.php

What you get depends on what you do. In other words, say you're doing something like

include($parts['dirname']);

The problem is that you would need to make sure that the "directory" is actually a file.


wwWebmasterWorldebsite.dom/index.php - is a file
wwWebmasterWorldebsite.dom - is not

kenchix1

2:31 am on Jul 22, 2005 (gmt 0)

10+ Year Member



thanks for the idea, but Im really new to php. what function/procedure should I use to determine if the directory is a file or not?

im using explode.

Anyango

6:51 am on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey

Why not you simply use Apache's "mod_rewrite" for this? That will make life simpler then you expect.

in 3 lines of .htaccess you ll be able to do all this.

Please let us know if you need assistance in that.

Thanks

Kami

kenchix1

3:26 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



thank you!

i don't know how to modify the .htaccess. :(

Anyango

6:53 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey,

That's Easy.

For example this following code , if put in a .htaccess file will send all .htm and .html requests to your index.php like this

RewriteEngine On
RewriteRule ^([^/]+)/?\.htm$ index.php?page=$1 [L]
RewriteRule ^([^/]+)/?\.html$ index.php?page=$1 [L]

For example if someone types

yourdomain.com/wow-this-is-a-test-page.html

and the page wow-this-is-a-test-page.html doesnt exist what this .htaccess will do is that it will take that
"wow-this-is-a-test-page.html"

and send it to your index.php as a parameter named "page"

so it will hiddenly change like

yourdomain.com/index.php?page=wow-this-is-a-test-page

and in your index.php you can easily put conditions on what do show on what page request. this way your urls will be too much friendly then simple "?this=that" thing.

This is just an example.. way more in it.

Thanks

Kami

kenchix1

6:27 am on Jul 26, 2005 (gmt 0)

10+ Year Member



many many thanks! :)

I'll try it. :)

kenchix1

7:38 am on Jul 26, 2005 (gmt 0)

10+ Year Member



sorry, I thought it was easy.

I saw line like this inside the .htaccess
RewriteCond %{HTTP_REFERER}!^http://somewebsite.dom/.*$ [NC]

then the last line says :

RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]

where do I insert those lines that you mentioned?

another thing is, it's not htm or html, it's actually a username

so people will type :

www.somewebsite.dom/username

then the "username" will be processed and they'll be redirected to their page.

Thank you very much for the help.