User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,232 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,755 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2291 | Replies: 7
Reply
Join Date: May 2006
Posts: 45
Reputation: petzoldt01 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
petzoldt01 petzoldt01 is offline Offline
Light Poster

Question Smart URL's

  #1  
Nov 7th, 2007
I am currently trying to understand how to rewrite URL's, but I am missing several pieces to the puzzle.

I will have a directory stucture similar to the following...

/
/apps
/lib
/config
/public
/public/index.php
/public/images
/public/css
/public/js

I want /public/index.php to be called first on nearly every url request. The only exceptions will be for requests going to /public/images, /public/css, and /public/js. Index.php will then examine the URL and determine what to do from there. I also need this to work on my local devel box and on the production server without having to manually change little bits of code that are scattered about.

I have looked into using mod_rewrite to get the desired effect, but I would rather use php to make descisions about what the URL is suppose to mean.

Using mod_rewrite, I will have a URL full of GET data, which is not desirable, especially if I am using GET data within my pages to transfer information. And to top that off, the number of arguments in the URL could change easily, so I will have to label each argument generically, and then reinterpret what each variable is referring to when I finally get to my main PHP script. Also, coming up with regular expressions to determine whether or not I am on my local box, and then trimming the url, is something I am not sure I know how to do.

PHP will allow me to resolve absolute paths into relative ones.
'http://localhost/local/mysite/showarticle/sports/112/' will be interpreted as '/showarticle/sports/112/' very easily without mistaking 'local' and 'mysite' as arguments that need to be processed.
And, I wont need to use any GET data to represent the action I want carried through, php will be able to interpret the URL internally without needing to modify the URL into 'http://localhost/local/mysite/public/index.php?' with a bunch of GET data at the end.

Ideally, I would like to set up a handler in apache (through .htaccess only), that calls index.php for any url that doesnt contain a file at the end ('http://localhost/images/pic.jpg' would be ignored). But as far as I know, handlers are only able to call cgi's (this could be bad information though), and I do not have php installed as a cgi.
I would like the handler to just straight up ignore the URL, call index.php, and pass the URL as an argument.

Is there any way to use the PHP method without using CGI's? If not, how hard is it to set up CGI's (never used em)?

If the PHP handler wont work, where do I start in doing a URL rewrite. I am starting to understand regular expressions, and all of the rewrite rules and rewrite conditions, but Im not exactly sure where to begin in parsing the URL and then making sure my index.php ends up with a valid url that it can interpret.

I know it was long, but thanks for pushing through it.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Solution Re: Smart URL's

  #2  
Nov 7th, 2007
yeah this is so long storey..you should keep your questions shorter otherwise ppl runaway

i did this yesterday for myself .htaccess


RewriteEngine On

RewriteRule ^\.htaccess$ - [F] 
RewriteRule ^\.jpg$ - [F]
RewriteRule ^\.html$ - [F]
RewriteRule ^\.css$ - [F]


RewriteRule ^([0-9]+),([0-9]+)$ /index.php?Language=$1&Index=$2 [L]
RewriteRule ^([0-9]+),([0-9]+),([0-9]+)$ /index.php?Language=$1&Index=$2&Category=$3 [L]
RewriteRule ^([0-9]+),([0-9]+),([0-9]+),([0-9]+)$ /index.php?Language=$1&Index=$2&Category=$3&State=$4 [L]
RewriteRule ^([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+)$ /index.php?Language=$1&Index=$2&Category=$3&State=$4&Position=$5 [L]
RewriteRule ^([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+)$ /index.php?Language=$1&Index=$2&Category=$3&State=$4&Position=$5&SubCategory=$6 [L]

if you need more about this.. search for apache rewriteRule
Reply With Quote  
Join Date: May 2006
Posts: 45
Reputation: petzoldt01 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
petzoldt01 petzoldt01 is offline Offline
Light Poster

Re: Smart URL's

  #3  
Nov 7th, 2007
@fatihpiristine
Thankyou much. I think I understand how to rewrite URL's after looking at your example.

I would still like to avoid using mod_rewrite if at all possible though. I would rather not have to rewrite the URL, but instead use php to interpret the URL as is. The idea of using a handler to do my logic seems more appealing, but I am still not sure how to do this.

Thanks again
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Smart URL's

  #4  
Nov 7th, 2007
i worked on php but i was not successful and i pick this way.
Reply With Quote  
Join Date: May 2006
Posts: 45
Reputation: petzoldt01 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
petzoldt01 petzoldt01 is offline Offline
Light Poster

Re: Smart URL's

  #5  
Nov 7th, 2007
I have been googling for a long time and ran across this little bit...

<Files index>
	SetHandler application/x-httpd-php
</Files>

Will this bit of code work if PHP is not installed as a CGI? And, why did this person use the SetHandler directive instead of ForceType.
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Smart URL's

  #6  
Nov 8th, 2007
Originally Posted by petzoldt01 View Post
I have been googling for a long time and ran across this little bit...

<Files index>
	SetHandler application/x-httpd-php
</Files>

Will this bit of code work if PHP is not installed as a CGI? And, why did this person use the SetHandler directive instead of ForceType.



could you post the link here..?? i wanna check it.
Reply With Quote  
Join Date: May 2006
Posts: 45
Reputation: petzoldt01 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
petzoldt01 petzoldt01 is offline Offline
Light Poster

Re: Smart URL's

  #7  
Nov 8th, 2007
This article goes through the whole process of configing the .htaccess all the way to actually interpretting the results with PHP. This post was put up in 2001, so Im thinking the PHP script is PHP4, but the apache .htaccess looks like it should work.
http://www.evolt.org/article/Search_Engine_Friendly_URLs_with_PHP_and_Apache/17/15049/index.html%22


This article is very similar but does not dig into the PHP details as much...
http://doughboy.wordpress.com/2007/1...urls-with-php/

And finally, here is the original article that I quoted. It seems to be for a windows/apache setup, although that shouldnt matter. He does not every say whether PHP is installed as a CGI binary or mod_php, so I am not sure about using "SetHandler" over "ForceType"..
http://www.brainhandles.com/2007/03/29/how-do-i-feed-data-to-a-script-without-question-marks-in-the-url/


All of these articles take a similar approach to setting up clean URL's, and it does not involve the use of mod_rewrite at all, albeit these are simple applications, so mod_rewrite may still be necessary for better control.

If anybody sees a problem with any of these examples, please let me know. I havnt been able to test it yet, but it seems the solution I was looking for is this.

<Files index>
	ForceType application/x-httpd-php
</Files>



This would work for a link like this... 
http://www.mysite.com/index/articles/sports/412/
...where you have a PHP script named 'index' (no .php at the end) in your web root along with the above code put into an .htaccess

thanks for your posts fatihpiristine, hit me back with some feedback on this latest post
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Smart URL's

  #8  
Nov 8th, 2007
thanks.. i ll work on this... i have so much free time if i do something really useful, i ll post you for sure.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:04 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC