Jump to content

Htaccess Help


kensbeijing
 Share

Recommended Posts

Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ http://profile.example.com/index.php?user=$1

I'v looked through many examples on htaccess files for redirect but not one of them work properly for my situation.I'm trying to make a member page where you can easily direct to a member's profile using a simple url e.g. www.example.com/jonny, but on the server side it goes to profile.example.com/index.php?user=jonnyThe one I am using at the moment will redirect, but it also changes the url in the address bar to the complicated one.What I need is an htaccess file that will redirect:www.example.com/jonnywww.example.com/jonny/example.com/jonnyexample.com/jonny/to profile.example.com/index.php?user=jonny but leaving the simple www.example.com/jonnySorry this isn't really php but there isn't a forum for htaccess files.

Edited by kensbeijing
Link to comment
Share on other sites

Hm..I think unless your server supports virtual domains and profile.example.com is virtual, you can't do it, because you're pointing to a different domain entirely - subdomains don't share directories or anything, so I'm not sure you can do it, otherwise I could rewrite something like example.com to example.google.com. It may be something that can be changed on the server, I don't know enough. The rules themselves would be easy enough, but wouldn't work without redirecting to the subdomain:RewriteEngine On#change example.com to www.example.comRewriteCond %{HTTP_HOST} !^example\.com$ [NC]RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]#translate example.com/jonny to profile.example.com/profile.php?user=jonnyRewriteRule ^example.com/(.*)$ profile.example.com/profile.php?user=$1

Link to comment
Share on other sites

Hm..I think unless your server supports virtual domains and profile.example.com is virtual, you can't do it, because you're pointing to a different domain entirely - subdomains don't share directories or anything, so I'm not sure you can do it, otherwise I could rewrite something like example.com to example.google.com. It may be something that can be changed on the server, I don't know enough. The rules themselves would be easy enough, but wouldn't work without redirecting to the subdomain:RewriteEngine On#change example.com to www.example.comRewriteCond %{HTTP_HOST} !^example\.com$ [NC]RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]#translate example.com/jonny to profile.example.com/profile.php?user=jonnyRewriteRule ^example.com/(.*)$ profile.example.com/profile.php?user=$1
Oh that's why it didn't work. Ok I have another idea, if example.com/jonny isn't a real directory, how do I redirect it to profile.example.com/jonny (but server side it's profile.example.com/index.php?user=jonny?
Link to comment
Share on other sites

RewriteRule example.com/(.*)$ /profile.example.com/index.php?user=$1 [R=301,L]That ought to do it, I think.

Link to comment
Share on other sites

Ok I'v hit another wall :) Well if I do this:RewriteRule ^user/([a-zA-Z0-9]+)/([a-z]+)$ user/index.php?user=$1&page=$2The location of the index page seems to move to a fake $2 directory, which means all my style sheets are in the wrong place. My style sheet atm is at "style/style.css", so the more fake directories I make e.g. /([a-z]+)/([a-z]+)/([a-z]+)$, the further away the style sheet gets. The only solution that I know to this is put the full url of the style sheet "http://example.com/user/style/style.css" which isn't very practical if I change the location of them.

Link to comment
Share on other sites

just add a leading forward slash to all your relative links: /style/style.css

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...