简体   繁体   English

Htaccess SEF网址重写

[英]Htaccess SEF url rewrites

Probably a simple solution for you guys but we are creating some landing pages for a customer's adwords account. 可能是一个简单的解决方案,但我们正在为客户的adwords帐户创建一些登录页面。 We have the pages created and are inserting the area and keyword using get requests in PHP. 我们创建了页面,并使用PHP中的get请求插入区域和关键字。

The url's currently look like this: 网址目前看起来像这样:

http://www.customersdomain.co.uk/index.php?keyword=locksmith&area=london http://www.customersdomain.co.uk/index.php?keyword=locksmith&area=london

Essentially I am looking for a htaccess rewrite rule that would allow this url to be entered: 基本上我正在寻找一个允许输入此URL的htaccess重写规则:

http://www.customersdomain.co.uk/areas/locksmith-london.html http://www.customersdomain.co.uk/areas/locksmith-london.html

With a view that the dynamic content of locksmith & london would be entered in to the page and could be replaced with other keywords such as locksmith & birmingham. 鉴于锁匠和伦敦的动态内容将被输入到页面中,并且可以被其他关键字替换,例如locksmith&birmingham。 We are aware this is bad practice for seo purposes but this customer has other reasons "wanting to appear local to his customer" for doing it. 我们知道这对于seo目的来说是不好的做法,但是这个客户有其他原因“想要在他的客户看来是本地的”这样做。

Any help would be great as it is not really my forte. 任何帮助都会很棒,因为它不是我真正的强项。

Since you are the admin and you don't need htaccess at all, you can use something like this in virtualhost context: 由于您是管理员而您根本不需要htaccess,因此可以在virtualhost上下文中使用类似的内容:

RewriteEngine on
RewriteRule ^/areas/(.+)-(.+)\.html$ /index.php?keyword=$1&area=$2 [L]

or 要么

RewriteRule ^/areas/([^-]+)-(.+)\.html$ /index.php?keyword=$1&area=$2 [L]

This is a very rudimentary way, but both work, if you have a limited set of values you could enclose them in the parenthesis like (london|paris|gotham) . 这是一种非常基本的方法,但两种方法都有效,如果你有一组有限的值,你可以将它们括在括号中(london|paris|gotham)例如(london|paris|gotham) There are more complex examples, specially if you have hundres of possibilities and you want to be very specific matching them you could even use RewriteMap. 还有更复杂的例子,特别是如果你有可能性并且想要非常具体地匹配它们你甚至可以使用RewriteMap。 But for starters try these ones, to make sure they are working use [R,L] to actually rewrite them and see how they really change in browser and then once you are sure they work, you can then remove the R flag so they get rewritten internally. 但是对于初学者尝试这些,以确保他们正在使用[R,L]来实际重写它们并看看它们在浏览器中是如何真正改变的,然后一旦你确定它们有效,你就可以删除R标志以便它们得到在内部重写。

In between tests, make sure yo clear your cache, or simply try "curl http://www.customersdomain.co.uk/areas/locksmith-london.html " to make sure cache from your browser is not interfering with your tests. 在两次测试之间,请确保您清除缓存,或者只是尝试“卷曲http://www.customersdomain.co.uk/areas/locksmith-london.html ”以确保浏览器中的缓存不会干扰您的测试。

Be sure to check the mod_rewrite documentation 一定要检查mod_rewrite文档

Oh, and about htaccess. 哦,关于htaccess。 I understand that you read somewhere to use .htaccess, and everyone in this world seems to think it is a magic file to add rewrites, but truth is it is only meant for users without access to main configuration file of HTTPD, it adds complexity as it happens in per-dir context, and it adds much overhead to the server. 我知道你读到了某处使用.htaccess,这个世界上的每个人似乎都认为这是一个添加重写的神奇文件,但事实是它只适用于没有访问HTTPD主配置文件的用户,它增加了复杂性它发生在per-dir上下文中,它给服务器增加了很多开销。 Your client will be thankful if you give their server maximum performance possible just by not using it. 如果您仅通过不使用服务器来提供服务器的最大性能,您的客户将会感激不尽。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM