简体   繁体   中英

Htaccess SEF url rewrites

Probably a simple solution for you guys but we are creating some landing pages for a customer's adwords account. We have the pages created and are inserting the area and keyword using get requests in PHP.

The url's currently look like this:

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:

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. 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.

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:

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) . 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. 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.

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.

Be sure to check the mod_rewrite documentation

Oh, and about 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. Your client will be thankful if you give their server maximum performance possible just by not using it. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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