Link to home
Start Free TrialLog in
Avatar of Luey
LueyFlag for United States of America

asked on

mod rewrite question

I am trying to make a RewriteRule for some customer profile pages.  I want them to be able to have a unique page address like  "www.mywebsite.com/JoesPlumbing".  I want to use "JoesPlumbing" as my url variable.  Below is what I tried and it did not work.  

RewriteRule ^/?(.*)$ /profile.php?page=$1  [QSA,NC,L]

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Try this

RewriteRule ^(.*)$ profile.php?page=$1  [QSA,NC,L]
Avatar of Luey

ASKER

Julian
That sends every link in the site to profile.php.
And how did you want to distinguish between all other URL's and what you specified in your post?

www.mywebsite.com/JoesPlumbing

The above makes it ambiguous as to whether you are calling a page or a profile

What you can do is the following

With the above you can add a RewriteCond like so (you should consider this as a matter of course)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Which will only redirect if the file or folder specified in the URL does not exist.

I would recommend you remove the ambiguity by choosing a URL structure as follows
www.mywebsite.com/profile/JoesPlumbing

Open in new window

And amending the rule to
RewriteRule ^profile/(.*)$ profile.php?page=$1  [QSA,NC,L]

Open in new window

Avatar of Luey

ASKER

How do other sites like facebook, twitter, etc do it then.
I changed the rule to this and it seems to work.

RewriteRule ^/(.*)$ /profile.php?page=$1  [QSA,NC,L]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luey

ASKER

Thanks Julian, do you know where I might find some examples of what you are talking about.  I am an uneducated old man and I have to figure everything out as I go.  I do not know how to set it up.
@Luey - please read the grading tips here (http://support.experts-exchange.com/customer/portal/articles/481419) - usual grade is an A - refer to article for guidelines on when and how to grade a question less than an A.

In response to your question - any of the major CMS systems out there (Drupal, Joomla, Wordpress) make use of this - looking at the .htaccess and source code for these systems will demonstrate how they are implementing it.
Avatar of Luey

ASKER

Hey

Thanks for sending me the link to the grading structure.  

"B is the grade given for acceptable solutions, or a link to an acceptable solution. A B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem. When closing the question, the asker should explain why a B grade was awarded".

I still was pretty much in the dark after your answer because I did not know what direction to go.  Now that you have made the comment of looking at the (Drupal, Joomla, Wordpress)  I do have a direction to go.  Always assume the person you are trying to teach something is a complete idiot, because some of us are. :)
I still was pretty much in the dark after your answer because I did not know what direction to go.
As per the guidelines the correct course of action is to post back and request further clarification - only after you have exhausted those avenues do you then consider the B grade and then always with a reason.

Your original question was why a particular mod_rewrite did not work - that was answered. The question then morphed into a new question about how other sites achieve a particular result. The confusion you mention is concerning the second part of the question and not the first - which was answered.

Always assume the person you are trying to teach something is a complete idiot, because some of us are. :)
I would have to disagree with you here - and to follow your advice is to ask for trouble. Many experts on this forum have been flamed because the asker thought that is exactly what the expert was doing and took offence. It is a fine line to walk and getting it write on a text only medium is a bit of hit and miss.
Avatar of Luey

ASKER

It is a fine line to walk and getting it write on a text only medium is a bit of hit and miss.

That I can agree on and that is why I have been paying for this service since 2009.  I do not appreciate the treatment you receive on sites like stackoverflow.


Many experts on this forum have been flamed because the asker thought that is exactly what the expert was doing and took offence.

If someone takes offense because they feel like their intelligence  has been insulted, they may not be as intelligent as they think they  are.