简体   繁体   English

向用户显示同一页面,但根据URL更改内容?

[英]Showing the same page to a user but change the content based on the URL?

I'm working on a site where for SEO reasons I need to have around 50 pages all with the same content, but with certain words swapped out based on the URL. 我在一个网站上工作,出于SEO的原因,我需要大约50页的内容都相同,但根据URL换出某些单词。 The certain words are all locations (ie UK, Spain, France etc). 某些单词在所有位置(例如英国,西班牙,法国等)。 So the content on the page will say "personal training courses UK or personal training courses Spain, personal training courses France). 因此页面上的内容将为“英国个人培训课程或西班牙个人培训课程,法国个人培训课程)。

Currently I have it so the URL is www.websitename.com/courses.php?location=uk. 目前,我拥有它,因此URL为www.websitename.com/courses.php?location=uk。 Then on the courses.php page I'm doing a $_GET to get the location parameter and then changing the content of the page based on this. 然后在courses.php页面上,我正在执行$ _GET以获取location参数,然后根据此参数更改页面的内容。 Ideally what I really want is for the URL to be www.websitename.com/courses/uk, www.websitename.com/courses/spain mainly for aesthetic reasons. 理想情况下,我真正想要的是将URL设置为www.websitename.com/courses/uk、www.websitename.com/courses/spain,主要是出于美学考虑。 Is there a rewrite rule to achieve this? 是否有重写规则来实现这一目标? I'm also open to alternatives so I can get the location in the URL using other methods to $_get. 我也对其他方法持开放态度,因此可以使用$ _get的其他方法来获取URL中的位置。

There are two ways of accomplishing this. 有两种方法可以实现此目的。

  1. Use a router 使用路由器

FastRoute and Klein.php are good choices. FastRouteKlein.php是不错的选择。

  1. .htacess rewrites .htacess重写

You can modify your .htaccess file to rewrite the URL for you. 您可以修改.htaccess文件来为您重写URL。 Effectively showing the user a different URL to what your application needs. 有效地向用户显示与您的应用程序所需内容不同的URL。

Options +FollowSymLinks  
RewriteEngine On 

RewriteRule ^courses/([a-zA-Z]+)$ courses.php?location=$1 [L,NC]

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

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