嗨,我想将我的 we 网站网址重写到我的主页,并将请求的网址参数作为变量传递
我的网站结构: index | gallery | animals
网址: www.mysite/gallery/animal
动物文件夹中.htaccess
文件 ::
Options +FollowSymlinks
RewriteEngine on
#RewriteRule ^(.*)$ http://www.mysite/$1 [NC]
我想在重写完成后在我的索引.php文件中获取原始 URL 或图库/动物?
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [NC]
现在,每个不指向现有文件夹/文件的URL都将重写为索引.php(在webroot文件夹中)。您可以使用 $_SERVER['REQUEST_URI']
访问原始网址。
编辑:
假设这是我们的网络根目录:
/
- dir/
- other-page.php
- .htaccess
- index.php
- page.php
以下是它的工作原理:
What user types (and sees in URL) What server sees and runs:
domain.com/ /index.php
domain.com/index.php /index.php
domain.com/page.php /page.php
domain.com/dir/other-page.php /dir/other-page.php
domain.com/dir/ /dir/
domain.com/hello/world/ /index.php
domain.com/i-like-cookies /index.php
domain.com/index.php/random/string /index.php
domain.com/dir/page.php /index.php
domain.com/page.php?game=super-mario /page.php?game=super-mario
domain.com/random/path?page=10 /index.php?page=10