![]() |
|
|
| Subject:
mod_rewrite help
Category: Computers > Internet Asked by: webguy123-ga List Price: $20.00 |
Posted:
30 Aug 2005 16:05 PDT
Expires: 29 Sep 2005 16:05 PDT Question ID: 562386 |
I have a coldfusion application and I am running Apache 2.0. I need help writing a rule: I have the following URL: http://localhost/profile.cfm?id=55614789 (the "localhost" will eventually be a domain name) What this does is load a specific persons page depending on the URL.ID variable passed in the browser (which I lookup from the database once the profile.cfm page is ran.) I need to allow a user's AccountName to load the page as well. For example: If someone enters "http://localhost/smith88" in the browser, I need it to lookup their unique AccountName and AccountID in the database and then really load "http://localhost/profile.cfm?id=55614789" | |
| |
| |
|
|
| There is no answer at this time. |
|
| Subject:
Re: mod_rewrite help
From: nozen-ga on 31 Aug 2005 14:06 PDT |
Step 1: create a file with your AccountName -> ID list in it. E.g.:
smith88 55614789
webguy123 11276534
... etc
Ensure that permissions are such that your Apache process can read it.
I'll assume it's in /usr/local/apache2/conf/username.txt for the following.
Step 2: Configure rewriting in the httpd.conf file. Here's a really
basic version; this would go at the end of your existing httpd.conf
file:
# Turn on rewriting
RewriteEngine on
# Define the text database that maps usernames to IDs
RewriteMap usernames txt:/usr/local/apache2/conf/usernames.txt
# Match /<something> - that's the /(.*)$ part
# Replace it with profile.cfm?id=
# Plus the result of looking up the <something> in the usernames.txt file
RewriteRule ^/(.*)$ profile.cfm?id=${usernames:$1|NOTFOUND}
# The |NOTFOUND above is a hack; if we see that string in the URL we should
# probably load some sort of "no such user" page...
RewriteCond ^.*NOTFOUND$ /notfound.html [L]
In the long run you will probably want to store the database in a DBM
file rather than as plaintext since the lookups will be faster - not
an issue for 10 names but definitely for 10,000! You may well also
want some sort of RewriteCond above the first RewriteRule to identify
pages or directories that aren't supposed to be rewritten.
I would recommend against a redirect. It will look "cleaner" and be
more search engine friendly if the user loads
http://example.com/username and the page loads directly (as this
example should do), rather than redirecting them to
http://example.com/profile.cfm?731892.
NoZen |
| Subject:
Re: mod_rewrite help
From: webguy123-ga on 31 Aug 2005 18:33 PDT |
Ok, so I can create some coldfusion code to append the username and userid to a text file everytime a new account is created. But, could your write out the mod_rewrite rule so I could try it? I understand very little on how to construct one myself. Thanks |
| Subject:
Re: mod_rewrite help
From: idcdiscount-ga on 02 Sep 2005 06:06 PDT |
It depends on what characters may contain urls at first level pages - http://www.domain.tld/(1level)/ Because if user account may contain dots you will receive an endless cycle with RewriteRule ^([^/]+)(/.*)? profile.cfm?id=$1 If your urls are like domain/file.ext this will work... For examle, look at http://www.idc-maxico.ru/ If you try to access a page http://www.idc-maxico.ru/catalog/company-555/ and there is no such a company at mysql db, you will get a message. So you should do something like this: .htaccess RewriteEngine On RewriteRule ^([^/\.]+)/?$ profile.cfm?id=$1 And a check in your script (it's PHP+MySQL): mysql_query("SELECT * FROM users WHERE id='".mysql_escape_string($_GET['id'])."'"); if(!mysql_affected_rows()) { header ("Location: /nouserfound.cfm"); exit; } About RewriteMap... It may take a really long time itself and plus map generation from db... |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |