我想重写我网站上的URL ...我该怎么办? [英] I want to rewrite an URL on my site... What can I do?

查看:89
本文介绍了我想重写我网站上的URL ...我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的URL www.example.com/(语言)/联系人重写为 www.example.com/con.htm ?lang =(language),那我应该用什么?

I want to rewrite my URL, www.example.com/(language)/contact into www.example.com/con.htm?lang=(language), so what should I use?

推荐答案

首先,请检查您在远程服务器上可以访问服务器根目录中的 .htaccess 文件。

First of all, check that you, on the distant server, have access to a .htaccess file in the root directory of the server.

现在,您首先需要输入

RewriteEngine On

以便进行重写。

现在,您可以使用神奇的 RewriteRule 令牌。它是什么?重写规则。

Now, you can use the magical RewriteRule token. What is it? A rewrite rule.

现在,它的工作方式非常简单:键入的URL仅在 RewriteRule ,其中(。*)代表您的变量,此处为(语言)。输出URL是服务器要爬网的URL,紧随其后,而我们在上面讨论的变量(。*)的内容将放在 $ 1 是。

Now the way it works is pretty simple: The URL typed in is to be typed just next to RewriteRule, with (.*) representing your variable, here (language). The output URL which is the URL to be crawled by the server is just after, and the content of the variable (.*) we talked about above will be placed where $1 is.

给我们:

RewriteEngine On
RewriteRule /(.*)/contact /con.htm?lang=$1

用作 .htaccess 的内容。

输入:

www.example.com/fr/contact

输出:

www.example.com/con.htm?lang=fr

它每次都有效!

可以根据需要添加任意多个 RewriteRule

Also you can add as many RewriteRules as you want!

这篇关于我想重写我网站上的URL ...我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆