I am trying to write a .htaccess
RewriteRule
for a profile page. I want the rule to query a SQL database for a user profile and if that data returns a result to load the profile.php
page. Example:
www.example.com/username
- or
www.example.com/user.name
- or
www.example.com/user.name123
and the like…
However, I have other pages like /login
, /registration
, /
, /chat
, and so on. Every time I try something I keep running into an issue.
I have tried the following:
RewriteEngine On
RewriteRule ^(login)$ login.php [QSA]
RewriteRule ^(logout)$ logout.php [QSA]
RewriteRule ^([w-]+)/?$ profile.php?pid=$1 [L,QSA]
I am trying to learn as much as I can but I am not comprehending the regex syntax and the conditions. The above rules let me use all the previous pages but it will catch everything else in the profile.php
page. What am I doing wrong?
2
Answers
Try This in your .htaccess file
make sure that in profile.php you have put certain condition to match the parameters and if not matches it shows error message or redirect you to 404 page
that would be nice
Please try following regex, I hope it will solve your problem.
you can always use this link to test your regex.