2014-05-24 175 views
-1

我有一個用於管理廣告的php腳本,但我想使用它友好的網址。如何將網址轉換爲htaccess中友好的網址

請給我htaccess的代碼,所有這方面的例子:

mydomain.com/index.php?page/login 
to 
mydomain.com/login 


mydomain.com/index.php?page=register&step=2 
to 
mydomain.com/register/step-2/ 


mydomain.com/index.php?page=articles&category=countries&article=afghanistan 
to 
mydomain.com/articles/countries/afghanistan 
+0

您是通過https://google.com搜索的嗎? –

+0

看看這個網站:http://www.generateit.net/mod-rewrite/index.php – SuperDJ

回答

0

你可以這樣做:(它不會是動態的)

Options +FollowSymLinks 

RewriteEngine On 
RewriteRule /login/(.*)$ /index.php?page/login 
RewriteRule /register/step-2/(.*)$ /index.php?page=register&step=2 
RewriteRule /articles/countries/afghanistan/(.*)$ /index.php?page=articles&category=countries&article=afghanistan 

這是短暫使用,並且必須最小化。

0

最好的辦法是創建一個index.php文件manaja請求的URL

// .htaccess 
Options -MultiViews 

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

和index.php文件

$url = rtrim($_GET['url'], '/'); 
$url = filter_var($url, FILTER_SANITIZE_URL); 
$url = explode('/', $url); 

例如,如果用戶呼叫URL //本地主機/登錄

// you include the file if exists 
include('rout to file/'.$url[0].'.php');