您好我想将我们的网站网址重写为我的主页并将请求的网址参数作为变量传递
我的网站结构:index | gallery | animals
网址:www.mysite / gallery / animal
.htaccess
文件::
Options +FollowSymlinks
RewriteEngine on
#RewriteRule ^(.*)$ http://www.mysite/$1 [NC]
我想在重写完成后在index.php文件中获取原始网址或图库/动物?
答案 0 :(得分:0)
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [NC]
现在每个不指向现有文件夹/文件的URL都会重写为index.php(在webroot文件夹中)。您可以使用$_SERVER['REQUEST_URI']
访问原始网址。
编辑:
让我们说这是我们的webroot:
/
- 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