简体   繁体   English

单个.htaccess文件,允许使用个性化网址和会话

[英]Single .htaccess file that allows vanity URLs and Sessions

I am trying to create an .htaccess file that does two things. 我正在尝试创建一个做两件事的.htaccess文件。 Firstly, I need it to allow me to have vanity URLs that pass to a page called profile.php. 首先,我需要它来让我拥有传递到名为profile.php的页面的个性网址。 Secondly, I want to be able to have sessions remain consistent regardless of whether the user types www. 其次,无论用户是否键入www,我都希望会话保持一致。 or not in the browser. 或不在浏览器中。 I have both of these capabilities working in two separate .htaccess scripts. 我在两个单独的.htaccess脚本中都具有这两种功能。 I need a single .htaccess file that will allow me to do both of these things. 我需要一个.htaccess文件,该文件可以让我完成上述两项操作。

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. 这使我可以进行一组会议而不必担心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! 将它们组合成单个.htaccess文件的任何帮助都将非常有用! 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: 但是您的路由需要删除http://www.website.com否则将发生隐式重定向:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM