我需要從URL中獲取值,而服務器不顯示頁面。例如,如果有人去:從url中獲取值而不顯示PHP中的頁面
www.example.com/123456
我想要得到 「123456」,並重定向到www.example.com。
www.example.com/123456不存在。
這可能與mod重寫和PHP以某種方式?
我需要從URL中獲取值,而服務器不顯示頁面。例如,如果有人去:從url中獲取值而不顯示PHP中的頁面
www.example.com/123456
我想要得到 「123456」,並重定向到www.example.com。
www.example.com/123456不存在。
這可能與mod重寫和PHP以某種方式?
例如,在你的.htaccess文件(假設與mod_rewrite的LAMP):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
而且index.php文件:
<?php
$url = $_SERVER['REQUEST_URI'];
// will output: /123456
echo $url;
?>
這個設置會將所有不指向實際文件或目錄的請求重定向到index.php。
完美!謝謝! – pgtips
你可以做簡單:
<?php
$data = $_GET['data'];
//Do something with the data
header('Location: http://www.example.com/');
?>
這將假定www.example.com/123456存在。它沒有。 – pgtips
不只是以某種方式,它是。檢查國防部重寫文件和教程。 – dbf