例如,对于我所拥有的网站:website.com/abcd,我需要提取' abcd'变量并存储在数据库中。如果用户访问website.com/abcd,则会重定向到404页面。我一直在修补.htaccess但没有到达任何地方。
答案 0 :(得分:1)
将下面的内容弹出到.htaccess文件......
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule . /index.php [L]
</IfModule>
...然后使用<?php print_r($_SERVER);?>
显示服务器允许您使用的变量。
上面的htaccess代码非常基本;如果被请求的文件/目录实际上不存在,请求将被重定向到./index.php
。
答案 1 :(得分:0)
在.htaccess
:
ErrorDocument 404 /handle_404.php
在handle_404.php中,您可以访问所需的所有信息:
<?php
header("HTTP/1.0 404 Not Found");
echo "The url you requested (${_SERVER['REQUEST_URI']}), does not exist.";
// do whatever else you want (e.g. persist to DB)