2013-08-22 57 views
0

我有我們用於我們所有用戶帳戶的php網頁腳本。我們的每個擁有帳戶的用戶都有一個他們可以使用的複製網站。該腳本自動生成他們複製的網址,像這樣。從網址中刪除字符

http://domain.com/?username

的用戶名是他們用自己的帳戶的用戶名。我想知道是否可以從url中刪除問號,以便他們可以使用url來訪問其複製的網站。

http://domain.com/username

我只是想簡單地從網址中刪除問號。這可能嗎?什麼是最好的方法來做到這一點?我可以用.htaccess做這種事嗎?

編輯:

我嘗試添加這對我的.htaccess文件,而不是當我去的URL喜歡http://domain.com/?username它消除了正確像我想的問題,但頁面被打破。沒有任何圖像正確顯示,並且沒有任何html正確顯示。

RewriteEngine On 

# This is to physically change what's in the browser's address bar using a client redirect 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?([^\ ]+) 
RewriteRule ^$ /%1? [R=301,L] 

# This is to internally rewrite on the server side 
RewriteCond %{QUERY_STRING} ^$ 
RewriteRule ^/?(.+)$ /?$1 [L] 

謝謝。

+1

是的,看看重寫規則。 – Brad

+0

你想如何處理:'http://domain.com/?q = abc&u = name&id = 1123'類型的URL?它應該變成:'http:// domain.com/q = abc&u = name&id = 1123'沒有'?' – anubhava

+0

是的,這正是它應該成爲的。我真正想要的是用戶可以通過輸入http://domain.com/username來訪問http://domain.com/?username。 –

回答

0

您可以使用PHP的str_replace功能:

<?php 
    $url = "http://domain.com/?username"; 
    $new_url = str_replace("?", "", $url); 
?> 

這取代的?所有實例沒有在url

+0

謝謝,但我實際上並不知道網址。我們有數百個用戶帳戶,因此用戶名可以是動態更改的任何內容。 –

0

你可以在htaccess url重寫規則的幫助下做到這一點。 使用下面的代碼來解決你的目的。

RewriteEngine on #turn on rewrite engine 
RewriteRule /username/(.*)/username ?username=$1