Sha*_*nov 15
在Apache配置文件[VirtualHost或Directory指令]中,或者在.htaccess文件中放入以下行:
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,NC,QSA]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
它会默默地将所有与有效文件名或目录(RewriteCond
在上面的代码中确保的)相对应的传入请求重定向到index.php文件.另外,如您所见,MultiViews
还需要禁用选项才能重定向工作 - 它通常与RewriteCond
我放在那里的这两个冲突相冲突.
在index.php中,您可以REQUEST_URI
通过$_SERVER['REQUEST_URI']
变量访问数据.您不应该通过任何URI GET
,因为它可能以不希望的方式污染您的Query-String数据,因为[QSA]
我们的RewriteRule中的参数是活动的.
小智 5
你应该使用重写规则..
在 apache (.htaccess) 中,是这样的:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
然后在您的 index.php 中,您可以在 php 代码中读取 $_GET['url'] 。
归档时间: |
|
查看次数: |
4961 次 |
最近记录: |