我需要在同一目录中有2个文件
index.php和room.php
如果用户访问www.example.com,我希望能够将其转到index.php
如果用户在网址中输入www.example.com/whateverelse/,则会将其重定向到room.php
另外,我想将URL的额外部分捕获到变量whateverelse
这甚至可能吗?
答案 0 :(得分:1)
是的,这是非常有可能的。在根目录中使用此代码.htaccess:
# load index.php by default
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=301,L]
# for all other requests load room.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(index|room)\.php).+)$ room.php [L,NC]