dongmufen8105 2010-10-01 19:33
浏览 80
已采纳

在PHP中构建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.

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.

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.

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

  • 写回答

9条回答 默认 最新

  • dou70260 2010-10-01 20:20
    关注

    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]
    

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大