How to redirect users to their specific subfolders?

48
February 11, 2019, at 5:00 PM

Ok, so I tried to Google it, make it by myself, but I just messed up my website, so after days of trying, I'm here to ask.

I want to redirect my users to their own subdirs. Examples:

  • www.example.com/username1 -> www.example.com/userpages/username1
  • www.example.com/username2 -> www.example.com/userpages/username2 and so on.

Of course, username can be almost anything, but www.example.com and the subdir userpages are fixed.

How can I do this with .htaccess?

Answer 1

What you appear to describe is a relatively straight forward redirect. However, the URL structure you have chosen will naturally create conflicts. What about URLs like /about and /contact etc.? Or is everything a username?

To redirect example.com/<username> to example.com/userpages/<username> you could do the following using mod_rewrite in .htaccess:

RewriteEngine on
RewriteRule ^([^/]+)$ /userpages/$1 [R,L]

Note that this assumes that every URL that contains a single path segment is a username.

READ ALSO
How to use chr() function in an array for cleaning strings from dangereous characters in PHP?

How to use chr() function in an array for cleaning strings from dangereous characters in PHP?

Hi everyone i was working on some php formsI am a newbie so i might used a really annoying way to solve my problem

30
Show concrete data of array with objects [duplicate]

Show concrete data of array with objects [duplicate]

This question already has an answer here:

33
No styling when converting DOCX into PDF

No styling when converting DOCX into PDF

I am trying to convert a DOCX file to PDF with PHPWordWhen I execute the script it looks like that some style elements are not converted

36