【问题标题】:Mod_Rewrite and website links structureMod_Rewrite 和网站链接结构
【发布时间】:2011-12-18 10:46:25
【问题描述】:

我有一个具有这种结构的网站

index.php/home.php/profile.php/news.php/photos.php

newsfeed.php - 用于新闻文章

photo.php - 用于照片

还有用户名供用户获取他的个人资料的短链接,例如

mysite.com/UserName

现在我在 .htaccess 中使用此代码来重写用户名的 URL

RewriteEngine on
RewriteOptions MaxRedirects=1
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule ^([^/]+)/?$ profile.php?u=$1 [L]

现在我想像这样重写我的所有链接,使其对 SE 友好

index.php   --> index
home.php    --> home
photos.php  --> photos
videos.php  --> videos

newsfeed.php?id=xx  --> news/xx
photo.php?id=xx     --> photo/xx

有什么想法吗?

【问题讨论】:

    标签: php .htaccess mod-rewrite seo


    【解决方案1】:

    这是我要做的:

    RewriteEngine on
    RewriteOptions MaxRedirects=1
    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    RewriteRule .* - [L]
    RewriteRule ^users/([^/]+)/?$ profile.php?u=$1 [L]
    RewriteRule ^news/([0-9]+)/?$ newsfeed.php?id=$1 [L]
    RewriteRule ^photo/([0-9]+)/?$ photo.php?id=$1 [L]
    RewriteRule ^videos/?$ videos.php [L]
    RewriteRule ^index/?$ index.php [L]
    RewriteRule ^home/?$ home.php [L]
    

    然后像这样添加它们。

    【讨论】:

      猜你喜欢
      • 2012-11-08
      • 2011-11-14
      • 2010-12-22
      • 2012-12-18
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 2018-04-07
      • 1970-01-01
      相关资源
      最近更新 更多