开发者

How to use JavaScript & .htaccess for SEO?

How can I use only JavaScript and/or .htaccess to map a request for:

http://example.com/map/new_york

to:

http://example.com/map?city=new_york

Without the user seeing the URL redirect?

UPDATE:

Since there seems to be a lot of confusion here, I'll provide开发者_如何学Python more detail. I want to accomplish Search Engine Optimization (SEO) for my map application. The map resides on my web server at http://example.com/map. I want to allow people to deep link to a city of their choosing, which is in the form of http://example.com/map/?city=new_york. Since I want SEO, the URL should instead look like: http://example.com/map/new_york.

Without using any type of server-side programming (PHP/Python/etc), how can I accomplish this use case with only JavaScript and/or .htaccess?


You cannot use JavaScript to do this.

However, you CAN do this via .htaccess, if you have mod_rewrite installed on the web server that is hosting your website.

See this link for creating "Rewrite" entries in your .htaccess file:

http://corz.org/serv/tricks/htaccess2.php

(there are plenty of resources on the internet to do this, search for ".htaccess rewrite"

UPDATED:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^map/([^/]+) /map?city=$1 [NC]

That should rewrite all requests to map/[ANYTHING] to /map?city=[ANYTHING]


var url = 'http://example.com/map/new_york';
var u = url.split("/");
document.write(u[0]+'/'+u[1]+'/'+u[2]+'/'+u[3]+'?city='+u[4]);

http://jsfiddle.net/NzXmd/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜