2014-05-24 139 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');