473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

seeking mod_rewrite solution

I have a people-networking type site in which each user has their own
profile page, with their user id encoded. So, for example, the web
address of their page might look like
"www.example.com/my_profile.php?user_id=fdjkhfh2489298hf298h3s0dhfx j".
I want the users to be able to choose their own web address that would
look like "www.example.com/Joel", and then when they type in that
address, they are automatically redirected to their profile page with
the more complex address.

I believe mod_rewrite is the solution to this?

Reading a little bit about mod_rewrite, I believe the rule I want is
something like the following:

RewriteRule ^/(.*) /redirect_user.php?user_name=$1

So 2 simple questions:
1) does this rule look like what I want?
2) how do I install and hook up the module, and do I write this rule
in the .htaccess file?

I'm brand new to mod_rewrite, so any help would be appreciated.

Mar 1 '06 #1
11 2016
I'm brand new to mod_rewrite, so any help would be appreciated.


Ask an Apache mailing list. You will get more help...
Mar 1 '06 #2
jo******@gmail.com wrote:
I have a people-networking type site in which each user has their own
profile page, with their user id encoded. So, for example, the web
address of their page might look like
"www.example.com/my_profile.php?user_id=fdjkhfh2489298hf298h3s0dhfx j".
I want the users to be able to choose their own web address that would
look like "www.example.com/Joel", and then when they type in that
address, they are automatically redirected to their profile page with
the more complex address.

I believe mod_rewrite is the solution to this?
Yes, it is.
Reading a little bit about mod_rewrite, I believe the rule I want is
something like the following:

RewriteRule ^/(.*) /redirect_user.php?user_name=$1


No, that wouldn't work too well, as it redirect every request to the
script. In general you want your rewrite rules to be as narrow as you
can. The pattern ^/\w+\/?/$ probably makes more sense.

I would also modify my_profile.php so it finds the user based on the
user name instead of doing a redirect to the page with the user id.
Don't really see a reason to do it in two steps.

Mar 2 '06 #3
jo******@gmail.com wrote:
I have a people-networking type site in which each user has their own
profile page, with their user id encoded. So, for example, the web
address of their page might look like
"www.example.com/my_profile.php?user_id=fdjkhfh2489298hf298h3s0dhfx j".
I want the users to be able to choose their own web address that would
look like "www.example.com/Joel", and then when they type in that
address, they are automatically redirected to their profile page with
the more complex address.

I believe mod_rewrite is the solution to this?
Yes, it is.
Reading a little bit about mod_rewrite, I believe the rule I want is
something like the following:

RewriteRule ^/(.*) /redirect_user.php?user_name=$1


No, that wouldn't work too well, as it redirect every request to the
script. In general you want your rewrite rules to be as narrow as you
can make them. The pattern ^/\w+\/?/$ probably makes more sense.

I would also modify my_profile.php so it finds the user based on the
user name instead of doing a redirect to the page with the user id.
Don't really see a reason to do it in two steps.

Mar 2 '06 #4
>The pattern ^/\w+\/?/$ probably makes more sense.

Yes, that is better, thank you.
I would also modify my_profile.php so it finds the user based on the
user name instead of doing a redirect to the page with the user id.
Don't really see a reason to do it in two steps.


I think you might have misunderstood what the my_profile.php page is.
It does not
redirect, it _is_ the user profile page, but based on the user_id as
given in the query
string (which is encoded in the query string, so decoded on the page),
it can get all
the information about the user from the database - it's a simple
database-driven page.

Mar 2 '06 #5
jo******@gmail.com wrote:
I think you might have misunderstood what the my_profile.php page is.
It does not
redirect, it _is_ the user profile page, but based on the user_id as
given in the query
string (which is encoded in the query string, so decoded on the page),
it can get all
the information about the user from the database - it's a simple
database-driven page.


I understood you just fine. What you are planning to do is to find the
user id based on the given user name in redirect_user.php, then
redirect to my_profile.php, which look up the user record using the id.
What I suggested was to look up the user record using the user name in
my_profile.php. There is no point in doing a redirect to the page when
you can rewrite directly to it.

Mar 2 '06 #6
Oh! Duh! Yes, of course - that makes perfect sense. I guess the only
reason I was thinking about using an intermediary redirect page was to
do any other pre-processing that might be necessary. For example, if
the "name" is "admin", then I would have the redirect page redirect the
user to the actual admin folder since in this case, this is not a
user's profile page, but an administrator trying to access the backend.
But, I guess this should probably be done using a RewriteCond?
Something like:

RewriteCond %{REQUEST_URI} !^admin.*$

Or something like that (I'm not too familiar with the syntax, although
I am somewhat familiar with regular expressions).

Mar 2 '06 #7
jo******@gmail.com wrote:
Oh! Duh! Yes, of course - that makes perfect sense. I guess the only
reason I was thinking about using an intermediary redirect page was to
do any other pre-processing that might be necessary. For example, if
the "name" is "admin", then I would have the redirect page redirect the
user to the actual admin folder since in this case, this is not a
user's profile page, but an administrator trying to access the backend.
But, I guess this should probably be done using a RewriteCond?
Something like:

RewriteCond %{REQUEST_URI} !^admin.*$

Or something like that (I'm not too familiar with the syntax, although
I am somewhat familiar with regular expressions).


It's easier to handle this special case by putting another rewrite rule
ahead of the one dealing with the profile page.

RewriteRule ^/admin/?$ /admin_page.php [L]
RewriteRule ...

The [L] flag tells mod_rewrite to not apply the subsequent rules.

Mar 2 '06 #8
Alright, I think I've got everything squared away, but now for the
potentially annoying part - how do I run the thing? Is it simply a
matter of including

RewriteEngine On
RewriteRule ^/admin\/?/$ /admin/index.php
RewriteRule ^/\w+\/?/$ /my_profile.php?user_name=$1

in the .htaccess file? Or do I need to include more in the .htaccess
file, or does this code have to go somewhere else besides the .htaccess
file? Is the mod_rewrite module already built in (I think it is)?
I've been trying to read about the mod_rewrite module on
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html, but I'm still
confused as to how to get the thing actually working. Ideally, the
complexity of a task should somewhat reflect the complexity of
implementing that task, but I don't know if that's the case here.

Mar 7 '06 #9
Alright, I think I've got everything squared away, but now for the
potentially annoying part - how do I run the thing? Is it simply a
matter of including

RewriteEngine On
RewriteRule ^/admin\/?/$ /admin/index.php [L]
RewriteRule ^/\w+\/?/$ /my_profile.php?user_name=$1
in the .htaccess file? (because I tried that and it didn't work) Or
do I need to include more in the .htaccess
file, or does this code have to go somewhere else besides the .htaccess

file? Is the mod_rewrite module already built in (I think it is)?
I've been trying to read about the mod_rewrite module on
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html, but I'm still
confused as to how to get the thing actually working. Ideally, the
complexity of a task should somewhat reflect the complexity of
implementing that task, but I don't know if that's the case here.

Mar 7 '06 #10
Ok, I'm beginning to understand the mod_rewrite module better. I
discovered the following important information. The RewriteEngine and
RewriteRule directives (which I will be using, possibly along with the
RewriteBase directive) are "Extensions". And the Apache server
documentation says this about "Extensions":

A directive with "Extension" status is provided by one of the modules
included with the Apache server kit, but the module isn't normally
compiled into the server. To enable the directive and its
functionality, you will need to change the server build configuration
files and re-compile Apache.

So, does anyone know how I would "change the server build configuration
files and re-compile Apache."?

Mar 7 '06 #11
jo******@gmail.com wrote:
Ok, I'm beginning to understand the mod_rewrite module better. I
discovered the following important information. The RewriteEngine and
RewriteRule directives (which I will be using, possibly along with the
RewriteBase directive) are "Extensions". And the Apache server
documentation says this about "Extensions":

A directive with "Extension" status is provided by one of the modules
included with the Apache server kit, but the module isn't normally
compiled into the server. To enable the directive and its
functionality, you will need to change the server build configuration
files and re-compile Apache.

So, does anyone know how I would "change the server build configuration
files and re-compile Apache."?


Joel,

Try an Apache newsgroup, like alt.apache.configuration. You don't have
to actually recompile Apache - just configure it correctly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 7 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phil Powell | last post by:
http://www.sitepoint.com/article/910/2] How can it be possible to use Apache's mod_rewrite module in such a way as to dynamically feed it variable information into the "RewriteRule" option? I...
1
by: Westcoast Sheri | last post by:
Hello. How do I do this: If a visitor types in any number after my url, I want mod_rewrite to convert it to my url/anotherpage.html?number=number_visitor_typed Example: ...
4
by: Support | last post by:
Hello, I am running RedHat & Apache. RedHat does not allow creating more that 32000 subdirectories in one folder due to #defined constant limitation in the core code. I need to display 47000...
1
by: Shabam | last post by:
In Apache there's a pretty powerful module called mod_rewrite. Is there anything like that in dot net?
3
by: Dr. No | last post by:
I am new to using mod_rewrite and am trying to rewrite a URL to pass values to my script so that: http://www.myclient.com/everything/animals/mammals/cats is transformed into ...
2
by: jwriteclub | last post by:
I have a question regarding back button functionality in an "ajaxy" web application. Here is the scenario: The user navigates to a page http://domain.com/app/. Since app/index.php file...
7
by: k3pp0 | last post by:
Hello. I'm trying to make use of "pretty URLs" with Apache's rewrite module. Here's what I want: http://foo.bar/index.php?download should be replaced with
11
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
With Apache's mod_rewrite module I can keep *.php files and load them as *.html files: # Make http//example.com/foo/bar.html load /home/site/foo/bar.php RewriteEngine On RewriteRule...
7
by: Dale | last post by:
again, i know this is OT...just move along to the next post if it bugs you. :) i had been trying to have this: project.66.204.32.110 from the client browser, map to a virtual host where the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.