用PHP构建SEO URL系统的好方法是什么? [英] What is a good way to have a SEO URL system built up in PHP?

查看:64
本文介绍了用PHP构建SEO URL系统的好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站中使用面向漂亮"和SEO的URL.

I want to have "pretty" and SEO oriented URLs in my site.

我已经为该站点建立了自己的微型框架,并且几乎所有内容都已完成.

I've build up my own tiny framework for this site and almost everything is complete now.

我仍然感到困惑的一件事是,我将使用漂亮的/SEO URLs系统.我知道有很多方法可以实现这一目标,并且我希望在此最佳实践/易于实现之间取得平衡.

One thing I'm still puzzled up is the pretty/SEO URLs system that I will use. I know there's many way to achieve this and I'm looking to balance best practices/ease of implementation on this one.

到目前为止,我一直在考虑使站点的所有URL指向一个特定的PHP文件(例如index.php),该文件将包含一个文件/URL字典,该文件/URL字典会将流量定向到正确的文件.

So far I'm thinking to have all URLs of the site to point to a specific PHP file (let's say index.php) that will contain a file/URL dictionary that will direct traffic to the correct file.

我真的不确定这是否是一种好方法……有人有更好的方法吗?我真正要避免的唯一事情是仅在.htaccess中执行此操作...

I'm really not sure if it's a good approach... Anyone have a better way to do this? The only thing I really want to avoid is to only do this in an .htaccess...

推荐答案

您将需要一个.htaccess文件(但无需在每次添加页面时都对其进行更改):

You'll need an .htaccess file (but you won't need to change it each time you add a page):

RewriteEngine On 
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]

现在在您的index.php中,您可以访问$_GET['url']中的请求的URL,将其映射到正确的文件,然后

Now in your index.php you can access the requested url in $_GET['url'], map it to the correct file and then include it.

注意:将RewriteBase注释放在此处,以防您需要取消注释,因为某些配置需要这样做.

Note: Put the RewriteBase comment in there in case you need to uncomment it as some configurations require this.

这篇关于用PHP构建SEO URL系统的好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆