0

What I mean by that is, so lets say I have a page for the user itself: localhost/blog/profile/ImUser1

I want to have other pages for the user like: localhost/blog/profile/ImUser1/my_subscribers Or localhost/blog/profile/ImUser1/my_posts

How do I create those kind of pages, like the subscriber page?

My current .htaccess code:

RewriteEngine On CheckCaseOnly On CheckSpelling On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^profile/(.*)$ /blog/profile.php?username=$1 [QSA,L] 

This allows for me to get to the userpage. And I need to have the username in the URL because thats how I extract information of who is subscribed to them.

Here is how I structured my PHP so far:

if(isset($_GET['username']) === true && empty($_GET['username']) === false){ $username = $_GET['username']; if(user_exists($username) === true){ echo 'Welcome to '.$username.' page!'; } }else{ echo 'Please enter a username in the URL'; } 

How do I tweak my PHP and .htaccess to make it work?

1

1 Answer 1

0

You could add an extra query-string variable to the request for profile.php which specifies the mode. Something like this:

RewriteRule ^profile/([a-zA-Z0-9_-]+)/?$ /blog/profile.php?username=$1 [L] RewriteRule ^profile/([a-zA-Z0-9_-]+)/([a-z][a-z_]*)/?$ /blog/profile.php?username=$1&mode=$2 [L] 

This way, a request for /blog/profile/some_user/some_mode will send the request to profile.php?username=some_user&mode=some_mode allowing your PHP script to check for a mode variable and render the page or redirect the page accordingly.

I've changed the username pattern from (.*) to [a-zA-Z0-9_-]+ to stop it slurping up forward-slashes, and to require it to be at least one character in length. And I've used [a-z][a-z_]* for the mode pattern to require it to start with lowercase letters and then allow underscores.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.