I want to rewrite my URL, www.example.com/(language)/contact into www.example.com/con.htm?lang=(language), so what should I use?
Asked
Active
Viewed 55 times
0
-
If you add answers, I will probably validate them if pertinent; it's a Wiki Q&A! – TheSola10 Oct 23 '15 at 08:06
1 Answers
0
First of all, check that you, on the distant server, have access to a .htaccess file in the root directory of the server.
Now, you first need to type
RewriteEngine On
in order for the rewrite to work.
Now, you can use the magical RewriteRule token. What is it? A rewrite rule.
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.
Giving us:
RewriteEngine On
RewriteRule /(.*)/contact /con.htm?lang=$1
as the content of .htaccess for what you asked.
Input:
www.example.com/fr/contact
Output:
www.example.com/con.htm?lang=fr
And it works everytime!
Also you can add as many RewriteRules as you want!
TheSola10
- 697
- 6
- 16
-
1`Options +FollowSymLinks` is not needed; it configures something complete unrelated – Sjon Oct 23 '15 at 08:11
-