我有一个链接www.example.com
和www.example.com/user/username
我如何重定向它,以便当有人访问www.example.com/username
时,他们得到与使用user
相同的东西?
因此这些链接将是相同的页面:www.example.com/user/username/profile
>www.example.com/username/profile
www.example.com/user/username/messages
>www.example.com/username/messages
www.example.com/user/username/chats
>www.example.com/username/chats
有什么我可以改变的吗?htaccess来实现这个结果?
最佳答案
您可以在站点根目录中使用此规则。htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!user/).+$ user/$0 [L,NC]