Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:47:52+00:00 2026-05-24T02:47:52+00:00

I want to do a redirection where a user enters their user name in

  • 0

I want to do a redirection where a user enters their user name in the URL and redirects to their profile, like this-> example.com/user/joe redirects example.com/user/profile.php?username=joe and obviously shows their profile.

I’ve looked around on how to do this but still haven’t managed to get it working.
How will I be able to do this? And where am I supposed to place my .htaccess file?

  • root
    • admin
    • includes
    • public
      • user
        • profile.php
      • index.php
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:47:54+00:00Added an answer on May 24, 2026 at 2:47 am

    From your directory it looks like ‘public’ directory is the document root for your website. So, place the .htaccess file there.

    None of this is tested. But this should get you off the ground. I would use mod_rewrite to achieve this. Something like this should go into your .htaccess file.

    RewriteEngine On
    RewriteRule ^user/(.+)$ user/profile.php?username=$1 [R,L]
    

    This should solve your problem. The [R] flag would cause Apache HTTPD to ask the browser to redirect and visit the new URL. Don’t use the [R,L] flag if you want the redirect to be internal without the user coming to know anything about it.

    Having said that, this is how I would really do it.

    RewriteEngine On
    
    # Canonicalize /user/foo to /user/foo/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^profile/([^/]+)$ /profile/$1/ [R=301,L]
    
    # Map /user/foo/ to foo's profile
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^profile/([^/]+)/$ profile/index.php?p=$1 [QSA]
    

    RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d would be to make sure that when a user has requested for a resource that is a valid file or folder present in the server, just don’t bother about all these redirect rules, go ahead and serve that file or folder right away.

    The first RewriteRule is to make sure that if the user forgets the trailing slash, the server asks the browser to redirect to the URL with a trailing slash. This is how Apache HTTPD behaves by default (perhaps because of mod_dir) and I would try to preserve the same behaviour here as well.

    The second RewriteRule makes sure that a request to http://example.com/user/foo/ is a valid URL but http://example.com/user/foo/bar/ is not. The [QSA] flag ensures that any parameters added to the URL are preserved.

    Without the [QSA] flag, http://example.com/user/foo/?ref=related+articles would internally redirect to http://example.com/user/profile.php?user=foo. With that flag, it would redirect to http://example.com/user/profile.php?user=foo&ref=related+articles which is what I prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i want something like this when user write www.test.com/6 in the behind it
I just want to get a quick htaccess redirection. ie: domain.com/subfolderGreen --> domain.com/index.php?folder=subfolderGreen (note
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I am using htaccess to redirect non-www to www like this: user typea: mydomain.com
I want to map a number of directories in a URL: www.example.com/manual www.example.com/login to
Currently I am using YOURLS PHP URL shorterning script. In their functions.php, seems like
I want to get the URL that the I'm feeling lucky button redirects to
I have problem with my .htaccess redirections. Say I want to change http://www.domain.com/login.php into
I want to run a simple JavaScript function on a click without any redirection.
want to know why String behaves like value type while using ==. String s1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.