PHP - Rewrite For Custom Url
Hi all
I have the following in my .htaccess file
RewriteRule ^([^/]+)/ /$1.php?q=$1 [L,QSA]
and this is great because any PHP page I create, such as 'about.php' can be rewritten as '/about/' - so that is all good.
the problem is, I also want to let users create their own custom URL's for their profiles in the root of the site, such as '/david-jones/' but because 'david-jones' is not actually a real PHP page (but rather a database entry), I cant use a rewrite rule as far as I can see.
Would the best solution be to piggy back the error 404 rewrite rule, so that if an actual PHP page isn't found, it takes them to the 404 error page which actually contains a script to lookup the users details, if the user details are not found, i'd show a "the page cannot be found" message.
Or is there a more elegant way to do this?
Thanks
Similar TutorialsThis topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=315930.0 I'm sure it's not much, but I'm not understanding something with custom error handlers: I've created a custom error handler, which I initially set when my page loads : set_error_handler(array ( new ErrorHandler(), 'handleError' ));
It seems to catch all internal PHP errors, such as if I: var_dump($non_existing_var); right after the set_error_handler.... Now, I have an object that throws an exception after: set_error_handler(array ( new ErrorHandler(), 'handleError' )); $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception ... I thought that with an error handler set, I could 'skip' the try/catch for it, but doing so, PHP spits out in its internal log: PHP Fatal error: Uncaught CorbeauPerdu\i18n\LocaleException: ....
My error handler doesn't catch it at all before, thus my page breaks!! If I want it to go through the error handler, I have to init my Locale with a try/catch and use trigger_error() like so: set_error_handler(array ( new ErrorHandler(), 'handleError' )); try { $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception } catch(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } ... Is this normal ? I thought one of the goals of the error_handler was to catch anything that wasn't dealt with? Thanks for your answers! I am having trouble rewriting a url, I have taken on a project that to rebuild a site that is over 7 years old and the current url structure is "http://www.mysite.com/?page=home" this i find crazy who uses "?page=" anyway am now creating the site again using a better structure of http://www.mysite.com/home.htm my problem is that the owner of the site has good google results with the current urls but wants them changing, and for the old ones to work too, i am trying to do this with .htaccess but the "?" in the url is causing massive problems with internal server errors. can anyone help me please it driving me nuts. Thanks in advance I want to rewrite this url
site.come/info.php?country=america&state=colorado&city=denver hello friends, that would help me alot , if i've 2 code all are of if and else code 1 $r = $_SERVER['HTTP_REFERER']; if (stripos($r, $refere) !== false) { echo "good"; }else{ echo "bad"; } code 2 if($line[hits] >= $limited){ echo "bad"; }else{ echo "good"; } both are 2 codes where the user should pass before it show good how then it be 1 code not 2 ( if x if y else y2 else x2 ) it like double sandwich Hi Guys, I no its only a partial PHP question but its still related to PHP... I have a URL .com/sites/0.php?Ter=144 and it takes you to a page and loads details with the id (ter) equalling 144 and displays all of 144's information... normal PHP stuff However I want to be able to put a Rewrite rule using a .htaccess (unless there is a better method!?) to get search engine frienly results. However I dont want the user to type .com/144 to bring up the Leeds branch. I want them to type .com/leeds and it bring up 144 (Leeds Branch). BranchName is the field I use for the branch name in my MySQL table. Is this possible? Also when I enter .com/sites/0.php?BranchName=Leeds that doesnt work either... Cheers, Sam Hi, I've a problem modifying the code which send parallel requests to get the status from getstatuses().I've two functions say public function getStatuses($idList) { } public function getid($id) { $status = array(); foreach ($id as $idList) { $status[] = $this->getStatuses($idList); } return $status; } the above getid() function sends the synchronous requests to the getstatuses() function and get the status back one after another.If you need to make 5 HTTP requests and each call takes a second, your app is delayed at least 5 seconds.Now,i want to rewrite the code(if possible two functions)that speeds up the results by sending all the requests and getting back the statuses at once.Something,other friends have developed is to reverse the getstatuses() and getid() functionality.Can anybody help me writing this code Thanks Hi,
I have upgraded my server from PHP 5.3.3 to version 5.5 and I'm now having a few problems with some code.
This line gives a fatal error of:
Call to undefined function session_is_registered()
if (session_is_registered("isAuthenticated") && ($_SESSION ['isAuthenticated'] = "loggedIn"))It appears this is depreciated? How can I solve this? This topic has been moved very early in the morning to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359281.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=357919.0 Hello everyone,How can i change the url when I am navigating from one page to another. for example if the existing url is like "www.example.com/product.php?name=xyz&q=service" ,I want to change it to "www.example.com/product/name/xyz/q/service" But I dont want to use .htacces. How can I do it using php functions only? This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=325762.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=332483.0 Hello friends, If i've link as following myownsite.000/index.php?r=5774 and i want to convert it to be myownsite.000/5774 i've tried .htaccess Code: [Select] RewriteRule (.*)\ index.php?r=$1 but didn't worked ! can anyone write it thanks This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=318852.0 Say my URL is http://www.example.com/catalog.php?category=hats&prodID=53 and I use Mod-rewrite to make it http://www.example.com/catalog/hats/53/ Can I still use $_GET['category'] to get the parameters? If so, how? This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=333344.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=346275.0 mod rewrite on easy php: EasyPHP says to set the following in apache config : http://www.easyphp.org/faq.php#0 Quote Uncomment LoadModule rewrite_module modules/mod_rewrite.so In <Directory "${path}/www"> section replace AllowOverride None by AllowOverride All I have done as the guide requested on easyPHP and restarted the easyPHP. writing a modrewite into the .htaccess following this guide: http://www.debian-administration.org/articles/136 Resulted in a .htaccess like so: Code: [Select] RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ /?route=$1 [PT] With this all in place and the url of the easyPHP index page is: http: //127.0.0.1:8080/testsite/ I added a link on the home page like this: http: //127.0.0.1:8080/testsite/route/hello but the link doesnt work. the .htaccess isn't kicking in it seems. Is it not meant to be seen in the php as: http: //127.0.0.1:8080/testsite/?route=hello So that i can grab the route from the $_GET? |