Forum Moderators: phranque
Heres my issue
i was following info from this link last
[webmasterworld.com...]
Here is what i have.
If i am understanding ReWrite URLs correctly, i should be able to thake
http//example.com/username
and on the CLIENT side it would call up
http://example.com/folder1/folder2/index.php?uid=1
Here is what i am trying to use to do that
RewriteEngine on
RewriteRule ^u([a-z0-9]+)\$ /folder1/folder2/index.php?uid=".$uid) [NC,L]
Youll notice at the end of the first [GROUP] i removed the ".html" and left the $ on the end
This is because people will be tying www.example.com/username
and not typing www.example.com/username.php
Also youll notice where it directing to ends in "/index.php?uid=".$uid)"
This is because where it says " uid=".$uid)" spits out the actual users registerd number into the browser
for example since i am the first, UID would be read as "/index.php?uid=1"
whom ever is the second person to register would be
/index.php?uid=2
3rd would be "/index.php?uid=3"
and so on
I am tryin to get "www.example.com/username"
to be spit back into the client browser as
"www.example.com/folder1/folder2/index.php?uid=1"
the number 1 on the end would be relative to the username typed into the client browser
[edited by: jdMorgan at 2:12 am (utc) on April 6, 2008]
[edit reason] example.com, tidied-up. [/edit]
First, mod_rewrite works on the server side, not the client side.
Second, mod_rewrite can do mainly two things: It can either redirect a URL to a different URL (detect a URL in a request from the client, and send a message back to the client telling it to ask for the resource using a different URL), or it can cause the server to use a different (non-default) filepath to provide content for a particular requested URL.
mod_rewrite works in the URL-to-filename translation phase of the Apache API, before any content-handlers or scripts are invoked. This is to say that it "looks at" the URL received in a request from a client, and either redirects that request, or changes the file that will be used to serve that request.
mod_rewrite cannot "change links" on your pages, or change anything in the content delivered to the client; It only handles the URL as it is being received in a request from the client.
As such, you are not going to be able to get mod_rewrite to create "userID" numbers unless the information needed to create the userID number is provided by the client in the URL somewhere. If you provide it in the URL directly, then it's a simple matter of transliteration; mod_rewrite can take it from a subdirectory path-part, from the subdomain (or even the domain name), or form a query string, and transform it into a properly-formatted query string for your script to use.
If, on the other hand, you want to translate a username to a user-ID number, then you need to do that in your script.
To put all of this into context, your problem should be phrased as:
"When www.example.com/username is requested from my server, I want to provide content from the filepath
/folder1/folder2/index.php?uid=1"
Since this is not possible, the closest you'll be able to get without using RewriteMap in httpd.conf (requires VPS or dedicated server) is this:
"When www.example.com/username is requested from my server, I want to provide content from the filepath
/folder1/folder2/index.php?user=username"
It will then be up to your script to look up the userID number based on the user=username name/value pair.
Jim
and be directed to
"www.example.com/folder1/folder2/index.php?user=username"
this is what i am looking for
AND
the page the user ends up on already has the code icnluded to udnerstand what uid=2 means and uid=700 means.
In the php page, it looks like this ( in code )
ww.example.com/folder1/folder2/index.php?uid=".$uid
at the end of the line, it says ".$uid "
this exact phrase changes the URL into a members number
This is why im trying to include that section into the ReWrite code.
Am i still on the right path? And.... well i made the attempt and i cant get it to work. grrrrr
Thanks for your help so far James
[edited by: tedster at 6:58 pm (utc) on April 17, 2008]
RewriteRule ^u([a-z0-9]+)$ /folder1/folder2/index.php?uid=$1 [NC,L]
Jim
when i setup the reqrite rules and save them in .htaccess
i then test it out by going to for example
www.example/anyusername ( example www.exampl.com/Jim )
my browser shows a blank white page with
/Jim
and thats it
its literally just a blank white page with that showing. As far as i know, this is a common result anytime ANY folder to my site is done, and that folder does not exist.
So with that in mind, it seems that the rewrite code is not working because if it was, then some kind of error would show up wouldnt it?
[edited by: tedster at 6:59 pm (utc) on April 17, 2008]
I clearly described how the rewrite that I posted works... You'll need to mind the details.
I have no idea how your script responds to missing/invalid usernames, so I can't tell you why you might get a blank page if you modified the rule so that it does not require the leading "u".
Jim
my example starts with ^u[group of text]
however that beginning of ^u i don't think is supposed to be there
DARN YOU INTERNET!
Ill test things out and see if it works or not
J thanks very much for your help. Please don't think that just because you cant tell me WHAT to do, that i didn't get help in finding out what i AM supposed to write.
Thanks again
[edited by: jdMorgan at 2:13 am (utc) on April 6, 2008]
[edit reason] tidied-up. [/edit]
i just re-read what ModRewrite does and now i understand
in my case a user would have to type in ( a dynamic url) something like:
http://example.com/folder1/folder2/index.php?uid=1
and mod rewrite would make it direct them to whatever i tell it to spit out with .htaccess
EXAMPLE: http://example.com/folder1/folder2/prodcut1.html
however this is completely not what im looking for
As a matter of fact this is backwards from what im looking for. And i hope someone can help me on this one.
My visitors are going to be coming to my site and typing in their browser, a url like,
http://www.example.com/user1
or " /user2 , or "/user3
and they are going to end up on a page of
http://example.com/folder1/folder2/index.php?uid=1
or
http://example.com/folder1/folder2/index.php?uid=2
or
http://example.com/folder1/folder2/index.php?uid=3
and so on depending on the USERNAME they type in.
Now my script (php) as far as i can tell, already recognizes all users as a number and automatically sends the visitor to the respective user # page.
But this only happens when you type in
http://example.com/userinfo.php?uid=1 or 2 or 3...
In this case i think i would need to a different rewrite working?
One to change /userinfo.php
into
/folder1/folder2/indes.php?uid=(VALUE)
Im just guessing but i hope im getting closer to the end on it
[edited by: tedster at 6:57 pm (utc) on April 17, 2008]
[edit reason] use example.com - it can never be owned [/edit]
In this case i think i would need to a different rewrite working?
One to change /userinfo.php
into
/folder1/folder2/indes.php?uid=(VALUE)
jdMorgan's explanation here of the difference between an external redirect and an internal rewrite helps to clarify a lot about what mod_rewrite does and doesn't do:
[webmasterworld.com...]
[edited by: Marcia at 5:04 am (utc) on April 11, 2008]
The examples of what users would be typing into their browser is above in my previous posts on this thread
Think you can lend a hand with this one?
I have looked at the doc over and over again but as stated in the previous post
it seems to me the doc describes for it to work in ONE direction
while ( ironically ) i need it to work in the opposite direction.
Or so i would belive
i THOUGHT i would need to use something like this
RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
because my visitors will arrive and type in a URL that has no extention like
.php or .html or anything else
and i would want their browser to pull data from the respective other dynamic url page while leaving their address bar unchanged
When someone types in /userinfo.php, they'll have to actually type in /user(VALUE).php in the browser to identify the user to the system - so there can be a unique point of reference the server can use to work with and "match" things up.
Then a directive can tell Apache that when /user(VALUE).php is "the request" made by the browser, then it should go ahead and deliver in response to that request
/folder1/folder2/indes.php?uid=(VALUE)
And leave what's in the user's browser address bar still looking like the /user(VALUE).php that they typed in, instead of "redirecting" to change the appearance and have the dynamic-looking URL showing in their browser address bar. Is that close?
It can be without any file extension, but the specifics will be in the regex (which is the hard part). In the Forum Library
Regular Expressions [webmasterworld.com]
Changing Dynamic URLs to Static URLs [webmasterworld.com]
-------------------------------
yes i am trying to do an INTERNAL redirect with the URL the user has typed to remain unchanged however i simply can not seem to accomplish this
My visitors are going to be coming to my site and typing in their browser, a url like,
http://www.example.com/user1
or " /user2 , or "/user3and they are going to end up on a page of
http://example.com/folder1/folder2/index.php?uid=1
or
http://example.com/folder1/folder2/index.php?uid=2
or
http://example.com/folder1/folder2/index.php?uid=3and so on depending on the USERNAME they type in.
RewriteRule ^u([a-z0-9]+)$ /folder1/folder2/index.php?uid=$1 [NC,L]That is all that mod_rewrite can do for you. You must do the rest in your index.php script.
RewriteRule ^user([a-z0-9]+)$ /folder1/folder2/index.php?uid=$1 [NC,L]
It only *LOOKS* like it's redirecting from the first part to the last part, but it isn't. And that's what's confusing about mod_rewrite - it's the opposite.
It's saying that if the browser requests user(ANYTHING) at the beginning, then deliver the dynamic(ANYTHING) at the end to the browser. And it leaves the URL requested in the browser alone. It'll still look like user(ANYTHING) in the browser address bar.
[edited by: tedster at 7:00 pm (utc) on April 17, 2008]
With this rule:
RewriteRule ^user([a-z0-9]+)$ /folder1/folder2/index.php?uid=$1 [NC,L]
In short form,
requests for URL example.com/user<something> are sent to file example.com/folder1/folder2/index.php?uid=<something>
To simplify the above description, I left out the detail that as the code is written now, the <something> part must be a string of lowercase or numeric characters only.
If you want to put links on your pages instead of having the user type in these URLs, then you must change your page-generation script to output links in the form "http://example.com/user<something>" -- mod_rewrite cannot change the links as they appear in your pages, it only affects requests as they arrive at your server.
If this is not working, then either the requirements were mis-stated, or there are other problems. Your note that you got a blank page indicates that the rule might in fact have worked. If the rule had not worked, you should have gotten a 404-Not Found error unless there is actually an existing file at the URL that you requested.
Points that seems to confuse:
"What is the real URL?" The real URL is whatever appears as a link on your pages, or whatever the user types in. By definition that is the URL; It is what a search engine will find and list in search results, for example. The appearance of a link on a page defines the URL, and nothing at all can be done that will change it.
"What is a server?" A server is a computer that accepts requests for "things" specified using "a universal naming method" and translates them into requests for files or script-generated content stored on (or produced by) the computer using whatever file-naming convention, operating system, or scripting language that computer may use. That is the purpose of a server: To make the "name" of a thing independent of the computer's internal operating conventions. This is why you don't need different URLs depending on whether the "things" you want to look at in your browser are stored on computers running Windows or Unix or Linux. A URL is simply what it says it is: A universal resource locator -- a platform-independent, universal name for a "thing."
"What does mod_rewrite do?" It grabs requests for URLs as they arrive at your server, and can change the file that that URL would otherwise be associated with. Or, it can send a response telling the client (browser or robot) to ask for the same "thing" again using a different URL. In the first case, this is called an internal rewrite, and in the second, an external redirect.
I hope that helps.
Jim
this will take http://www.example.com/example
and direct people to http://example.com/modules/yogurt/index.php?uid=1
yes i know this is a redirect but that will work just fine.
However it is currently CASE SENSITIVE (darn-it)
im not sure where to place " u([a-z0-9]+) "
First of all do i need the + sign in the end of it?
i simply want to let the server understand
DOMAIN/Non CaSe SEnsiTiVe TeXt
the part after the " / " can be whatever i have assigned in the RewriteRule
[edited by: tedster at 6:54 pm (utc) on April 17, 2008]
[edited by: jdMorgan at 7:36 pm (utc) on April 17, 2008]
[edit reason] use example.com - it can never be owned [/edit]