2016-03-29 28 views
0

我想將斜線後面的文本用作變量。 爲例:將斜線後的文本轉換爲HTACCESS變量

www.mydomain.com/client1 

這相當於

www.mydomain.com/index.php?customer=client1 

我試着使用:

$customer = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); 

但沒有奏效。

我想,我必須這樣做,在.htaccess文件或者也許使用基本名稱

回答

2

,你需要編寫HTACCESS

<ifmodule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /yourDirectory/ 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /yourDirectory/index.php [L] 
</ifmodule> 

以上的htaccess點的所有網址以index.php

將此內容添加到HTACCESS後,您可以使用您的PHP代碼訪問index.php下的basename() URI。

+0

這項工作像魔術,謝謝:) –

+0

y,你總是歡迎.. :) – ameenulla0007