单个.htaccess文件,允许虚荣URL和会话

I am trying to create an .htaccess file that does two things. Firstly, I need it to allow me to have vanity URLs that pass to a page called profile.php. Secondly, I want to be able to have sessions remain consistent regardless of whether the user types www. or not in the browser. I have both of these capabilities working in two separate .htaccess scripts. I need a single .htaccess file that will allow me to do both of these things.

This allows me to do the vanity url:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://www.website.com/profile.php?u=$1 [NC]

This allows me to have a single set of sessions without worrying about www.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^website\.com
RewriteRule ^(.*)$ http://www.website.com$1 [R=permanent,L]

Any help combining these into a single .htaccess file would be great! Thanks!

You want to redirect before you route. But your route needs to have the http://www.website.com removed otherwise there will be an implicit redirect:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [R=permanent,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ /profile.php?u=$1 [NC,L]