1

I am working on a new website bud I want to create a nice looking urls for my users. I don't know anything of htaccess and could not find my solution on google.

I need to link:

  • user.mywebsite.com to>> mywebsite.com/users/user
  • user2.mywebsite.com/contact to>> mywebsite.com/users/user2/contact

Some links may not be linked like:

  • www.mywebsite.com may not link to mywebsite.com/users/www

Is this possibe to do with htaccess? If yes can someone explain it to me?

NG_
  • 6,895
  • 7
  • 45
  • 67
Rednas
  • 609
  • 5
  • 12

3 Answers3

6

Using mod_rewrite, you can try:

RewriteEngine On

# the request URI doesn't already start with /users/
RewriteCond %{REQUEST_URI} !^/users/

# host doesn't start with www
RewriteCond %{HTTP_HOST} !^www\.  [NC]

# host starts with something else
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mywebsite\.com$  [NC]

# rewrite
RewriteRule ^(.*)$ /users/%1/$1  [L]

This will make it so when someone enters http://joe.mywebsite.com/some/page.html they will be served the file in /users/joe/some/page.html

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Why it give me 500 error? I am using codeigniter and using pretty url without index.php exists on my htaccess, can you help me? Thanks in advance. – Anggie Aziz Jun 08 '14 at 03:31
-1

Redirecting your old links to new ones.

Redirect user.mywebsite.com mywebsite.com/users/user
Redirect user2.mywebsite.com/contact mywebsite.com/users/user2/contact
Ahmet Can Güven
  • 5,392
  • 4
  • 38
  • 59
  • sorry this isn't what i'm looking for. need someting to get it work always with every account – Rednas Dec 13 '11 at 18:23
-1

You can take a look at VirtualDocumentRoot

e.g. the documents for www.user.isp.com are found in /home/user/.

# include part of the server name in the filenames
VirtualDocumentRoot /www/hosts/%2/docs

# single cgi-bin directory
ScriptAlias /cgi-bin/ /www/std-cgi/
MiniGod
  • 3,683
  • 1
  • 26
  • 27