| | |
Smart URL's
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
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.
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.
yeah this is so long storey..you should keep your questions shorter
otherwise ppl runaway
i did this yesterday for myself .htaccess
if you need more about this.. search for apache rewriteRule
otherwise ppl runaway i did this yesterday for myself .htaccess
PHP Syntax (Toggle Plain Text)
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
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
@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
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
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
I have been googling for a long time and ran across this little bit...
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.
PHP Syntax (Toggle Plain Text)
<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.
•
•
•
•
I have been googling for a long time and ran across this little bit...
PHP Syntax (Toggle Plain Text)
<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.
•
•
Join Date: May 2006
Posts: 45
Reputation:
Solved Threads: 0
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.
thanks for your posts fatihpiristine, hit me back with some feedback on this latest post
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.
PHP Syntax (Toggle Plain Text)
<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
![]() |
Similar Threads
- Shortcuts wont work (Viruses, Spyware and other Nasties)
- Computer Randomly restarts (Windows NT / 2000 / XP)
- hi to all (Community Introductions)
- Fixes for Specific Infections (Viruses, Spyware and other Nasties)
- Desktop Background Hijacked-NEW Problem(! Smart Security) (Viruses, Spyware and other Nasties)
- Umm a little question for you smart ppl!;-) (Geeks' Lounge)
Other Threads in the PHP Forum
- Previous Thread: PHP and cgi-bin
- Next Thread: problem comparing strings
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alerts apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop overwrite parse paypal pdf php problem query radio random recursion redirect regex remote script search securephp server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube






if i do something really useful, i ll post you for sure.