Title: Redirect if url is http://siteurl/username
Last modified: August 20, 2016

---

# Redirect if url is http://siteurl/username

 *  [iyoworks](https://wordpress.org/support/users/iyoworks/)
 * (@iyoworks)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/redirect-if-url-is-httpsiteurlusername/)
 * I’m working on a client site in which students will have ‘portfolios’. The portfolio
   page is just a page that pulls a user’s projects (my custom post type).
 * The url structure for the portfolios is [http://siteurl/portfolios/?username](http://siteurl/portfolios/?username)
 * What I want is for **[http://siteurl/username](http://siteurl/username) **to 
   redirect to **[http://siteurl/portfolios/?username](http://siteurl/portfolios/?username)**
 * Does anyone have any idea on how to get this setup?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Rebecca O'Brien](https://wordpress.org/support/users/rjmastey/)
 * (@rjmastey)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/redirect-if-url-is-httpsiteurlusername/#post-2358436)
 * Two ways to do it
    1. Download the Page Link To plugin, create a page for each
   student and set their portfolio as the redirect link <– easy! 2. Create a custom
   redirect option in .htaccess/wp_rewrite to handle this <– hard-ish
 * Depending on how many students there are, I’d honestly go with the easy option.
 *  Thread Starter [iyoworks](https://wordpress.org/support/users/iyoworks/)
 * (@iyoworks)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/redirect-if-url-is-httpsiteurlusername/#post-2358439)
 * Thanks. The site will probably start with 30-50 students and will grow as more
   student go through the program. I’m not too versed with the wp_rewrite tag or
   the .htaccess file. How would I get the second option to work?
 *  Thread Starter [iyoworks](https://wordpress.org/support/users/iyoworks/)
 * (@iyoworks)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/redirect-if-url-is-httpsiteurlusername/#post-2358465)
 * I created a work around. This is the code I’m using in my functions.php file:
 *     ```
       //redirect to student profile if [homeurl]/[username] is the current url.
       if (!is_admin()) {
   
       $url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
       $url = ereg_replace("(https?)://", "", $url);
       $token = explode('/', $url);
       $token = $token[sizeof($token)-1];
   
       $shortPortfolioUrl = ereg_replace("(https?)://", "", (home_url(''.$token.'')));
       if ($url == $shortPortfolioUrl) {
       	if (username_exists($token) != null ) {
       		$location = home_url().'/portfolios/?'.$token;
       		wp_redirect( $location );
       		exit;
       	}
       }
   
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Redirect if url is http://siteurl/username’ is closed to new replies.

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 3 replies
 * 2 participants
 * Last reply from: [iyoworks](https://wordpress.org/support/users/iyoworks/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/redirect-if-url-is-httpsiteurlusername/#post-2358465)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
