我如何为此设置URL重写?

时间:2012-10-01 13:25:00

标签: .htaccess url-rewriting

我尝试了一些不同的东西,但没有成功。

基本上,我有一些非常难看的网址。

http://example.com/index.php?p=1_4_Contact-Us
http://backlinktuners.com/index.php?p=1_2_Services

我希望他们只是简单,

http://example.com/contact-us

我将如何做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)

为了清楚(因为要求URL 某些其他URL在此上下文中没有任何意义),听起来你要求客户端重定向,这意味着什么时候有人在其网址栏中输入http://backlinktuners.com/index.php?p=1_2_Services,他们的请求会被重定向到http://example.com/contact-us,这将替换其地址栏中的其他网址,然后他们的浏览器会在http://example.com/contact-us(旧版本)请求资源URL被抛出窗口。)

尝试将这些规则添加到文档根目录中的htaccess文件中:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=[0-9_]+_Contact-Us [NC,OR]
RewriteCond %{QUERY_STRING} ^p=[0-9_]+_Services [NC]
RewriteRule ^/?index.php$ /contact-us [L,R=301]

当然,如果您在http://example.com/contact-us没有任何内容,浏览器只会看到404错误。

相关问题