php - (SEO + htaccess) 带有分页和页面详细信息的页面列表

标签 php .htaccess mod-rewrite pagination seo

我对 SEO - PHP 有疑问。

我有 2 个页面:新闻列表页面和新闻详细信息页面。

但是,从 SEO 的角度来看,如何区分 URL 中的这两个页面?

目前,我正在使用这些 URL:

  • www.site.com/it/news/page-1/- www.site.com/it/news/page-2/... (带分页的新闻列表)
  • www.site.com/it/news/title-news-detail/ (新闻详情)

我的文件.htaccess代码:

# first parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ index.php?lang=$1 [L]
#

# second parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/$ index.php?lang=$1&page=$2 [L]
#

# third parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ index.php?lang=$1&page=$2&param=$3 [L]

我的问题是读取第三个参数,因为我不知道这是页码还是新闻标题..

最佳答案

像这样:

# ignore files and directories from all rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# first parameter
RewriteRule ^([^/]+)/$ index.php?lang=$1 [L,QSA]

# second parameter with pagination
RewriteRule ^([^/]+)/page-(\d+)/$ index.php?lang=$1&page=$2 [L,QSA]

# second parameter with title
RewriteRule ^([^/]+)/([^/]+)/$ index.php?lang=$1&title=$2 [L,QSA]

# third parameter
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ index.php?lang=$1&page=$2&param=$3 [L,QSA]

关于php - (SEO + htaccess) 带有分页和页面详细信息的页面列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33809811/

相关文章:

php - 将变量值限制为某些预定义值

PHP 命名空间 : Function Loading

.htaccess - 301 将所有丑陋的永久链接从旧站点重定向到新站点

.htaccess - 重写基本: from specific url to another specific url

mod-rewrite - SEO 友好 URL 问题

wordpress - 301 在 wordpress 中从非 www 重定向到 www

php - 如何对查询结果进行随机排序并选择随机行。 (MySQL)

php - 更改选择标签属性值

regex - 如何为多个目录创建 htaccess 重定向

php - .htaccess - 子域的 DocumentRoot