htaccess url rewriting - 隐藏URL上的文件扩展名

时间:2013-03-17 00:19:21

标签: .htaccess rewrite friendly-url

目前

如果我添加类似

的href,它已经有效了

<a href="central-cliente">Click here to go to the client center</a>

但是我的大多数链接都是这样的,它在URL中显示clientarea.php - 应该覆盖它并且是中心客户端,如.htaccess

中所设置的

<a href="clientarea.php">Click here to go to the client center</a>

问题

我希望客户端看到友好的网址,即使他点击了不友好的网址(.php,.html等)

的.htaccess

Options +FollowSymlinks
RewriteEngine On
Options -MultiViews
RewriteBase /painel/

RewriteRule ^central-cliente$ ./clientarea.php [L,NC]
RewriteRule ^registro$ ./register.php [L,NC]
RewriteRule ^entrar$ ./clientarea.php [L,NC]
RewriteRule ^sair$ ./logout.php [L,NC]
RewriteRule ^whois-dominio$ ./domainchecker.php [L,NC]
RewriteRule ^pagina-inicial$ ./index.php [L,NC]
RewriteRule ^sua-conta$ ./clientarea.php [L,NC]
RewriteRule ^base-conhecimento$ ./knowledgebase.php [L,NC]
RewriteRule ^tickets-suporte$ ./submitticket.php [L,NC]
RewriteRule ^status-servidor$ ./serverstatus.php [L,NC]
RewriteRule ^recuperar-senha$ ./pwreset.php [L,NC]
RewriteRule ^status-servidor$ ./serverstatus.php [L,NC]
RewriteRule ^tickets-suporte-geral$ ./submitticket.php?step=2&deptid=1 [L,NC]
RewriteRule ^central-cliente$ ./clientportal.php [L,NC]
RewriteRule ^meus-dados$ ./clientarea.php?action=details [L,NC]
RewriteRule ^meus-servicos$ ./clientarea.php?action=products [L,NC]
RewriteRule ^meus-dominios$ ./clientarea.php?action=domains [L,NC]
RewriteRule ^meus-orcamentos$ ./clientarea.php?action=quotes [L,NC]
RewriteRule ^minhas-faturas$ ./clientarea.php?action=invoices [L,NC]
RewriteRule ^meus-tickets$ ./supporttickets.php [L,NC]
RewriteRule ^afiliados$ ./affiliates.php [L,NC]
RewriteRule ^meus-emails$ ./clientarea.php?action=emails [L,NC]
RewriteRule ^sair$ ./logout.php [L,NC]
RewriteRule ^enviar-ticket$ ./submitticket.php?step=2&deptid=1 [L,NC]
RewriteRule ^download$ ./downloads.php [L,NC]
RewriteRule ^carrinho$ ./cart.php [L,NC]
RewriteRule ^extras$ ./cart.php?gid=addons [L,NC]
RewriteRule ^renovar-dominio$ ./cart.php?gid=renewals [L,NC]
RewriteRule ^registrar-dominio$ ./cart.php?a=add&domain=register [L,NC]
RewriteRule ^pagamentos-multiplos$ ./clientarea.php?action=masspay&all=true [L,NC]
RewriteRule ^adicionar-credito$ ./clientarea.php?action=addfunds [L,NC]
RewriteRule ^cartao-credito$ ./clientarea.php?action=creditcard [L,NC]
RewriteRule ^base-de-conhecimento$ ./knowledgebase.php [L,NC]
RewriteRule ^downloads$ ./downloads.php [L,NC]
RewriteRule ^status-da-rede$ ./serverstatus.php [L,NC]
RewriteRule ^sub-contas$ ./clientarea.php?action=contacts [L,NC]
RewriteRule ^emails-enviados$ ./clientarea.php?action=emails [L,NC]
RewriteRule ^mudar-senha$ ./clientarea.php?action=changepw [L,NC]
RewriteRule ^afiliados$ ./affiliates.php [L,NC]
RewriteRule ^suporte$ ./submitticket.php?step=2&deptid=1 [L,NC]
RewriteRule ^transferencia-dominio$ ./cart.php?a=add&domain=transfer [L,NC]

1 个答案:

答案 0 :(得分:1)

不幸的是,您的映射没有统一的模式。您必须首先有一个规则高于所有其他规则以防止无限重定向循环

# prevent endless loop    
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

然后逐个添加反向映射以获取简单的URL

RewriteRule ^clientarea.php$ central-cliente [R,L]

或有条件,如果您有查询字符串

RewriteRule ^clientarea.php?action=details$ meus-dados [R,L]

工作,因为?action=details不是网址路径的一部分。您必须拥有RewriteCond %{QUERY_STRING}

RewriteCond %{QUERY_STRING} action=details
RewriteRule ^clientarea.php$  meus-dados? [R,L]

最后的问号?会抑制替换网址中的查询字符串。

也许,你可以使用RewriteMaptxt至少对于简单的一对一重定向和维护简单文本文件中的映射列表。但这与你的.htaccess中有一长串RewriteRule s没什么不同。