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

LueyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Try this

RewriteRule ^(.*)$ profile.php?page=$1  [QSA,NC,L]
0
LueyAuthor Commented:
Julian
That sends every link in the site to profile.php.
0
Julian HansenCommented:
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

0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

LueyAuthor Commented:
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

0
Julian HansenCommented:
They use a number of different techniques

1. is to have all urls go through a single script which then routes based on the path, filename and paramters

2. They use a method described above to split urls up based on path variables

There are various different ways of handling it - depends on your specific circumstances.

I route everything (that does not exist) through an index.php file that parses the URL and then routes internally based on the path variables, filename etc.

The ideal situation is to design your site around the routing - not try and bang it on at the end - it makes it much easier if you design for it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LueyAuthor Commented:
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.
0
Julian HansenCommented:
@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.
0
LueyAuthor Commented:
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. :)
0
Julian HansenCommented:
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.
0
LueyAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.