使用WamServer,我用Generate It!過度寫這樣重寫國防部仍返回原始地址
原始URL網址:
http://localhost/CMS/foo.php?id=2&slug=eyeglasses
的重寫URL:
http://localhost/2/eyeglasses.php
的規則,網站給我的是
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.php$ /CMS/foo.php?id=$1&slug=$2 [L]
但是這仍然是恢復原來的URL
http://localhost/CMS/foo.php?id=2&slug=eyeglasses
能否請你讓我知道我做錯了什麼?
更新
更明確!我有一個index.php
包含了像
echo '<a href="foo.php?id='. $theID .'&slug='. $slug .'" class="list-group-item" data-id="'.$theID.'">'.$theName.'</a>';
一個環節,現在我們用戶foo.php
登陸網址看起來像
http://localhost/CMS/foo.php?id=1&slug=eyeglassess
是否正確?我想這樣做是顯示
http://localhost/2/eyeglasses.php
,而不是原來的URL
請說明。你是否從瀏覽器發送URL'http://localhost/CMS/foo.php?id = 2&slug = eyeglasses',並期待它在瀏覽器地址欄中被重寫爲'http:// localhost/2/eyeglasses .php「,或者你是否從瀏覽器發送了'http:// localhost/2/eyeglasses.php',它將重定向而不是內部重寫爲'http://localhost/CMS/foo.php?id = 2&slug = eyeglasses'?如果第一個問題是你所看到的,那通常不是如何使用mod_rewrite,並且需要幾條額外的線來制定。 –
換句話說,mod_rewrite不能在你的代碼中自動轉換URL或者在野外轉換。它通常用於將乾淨的URL路由到更復雜的應用程序中。 –
感謝邁克爾,我實際上有一個'index.php'頁面,我有鏈接'\t echo''.$theName.'';'現在在foo.php中的'foo.php'而不是'http:// localhost/CMS/foo.php?id = 2&slug = eyeglasses'我想在網址 – Behseini