使用PHP SEO友好的URL来动态URL [英] SEO Friendly URL to Dynamic URL using PHP

查看:150
本文介绍了使用PHP SEO友好的URL来动态URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个这样的网址

Currently I have a url like this

http://<client_name>.website.com/index.php?function_name&cat=32

我想设置的东西,使我们的营销人可以发布URL的喜欢

I want to set things up so that our Marketing people can publish url's like

http://<client_name>.website.com/<parent_category>/<category>   

猫= XX将在最后产生的&LT;类别&GT; 只。但市场要使用父类的活动。目前,我们通过所有的HTML根目录的URL通过index.php文件(这将成为重要的更新版本)。

The "cat=XX" will be generated of the last <category> only. But marketing wants to use the parent category in their campaigns. Currently we pass all of URL's through index.php in the html root directory (this will become important later).

我已经尝试了几种解决方案,包括:

I've tried several solutions including:

  1. 的mod_rewrite - 这种方法的问题是,它变成一个巨大的.htaccess文件,因为我们需要写每类规则

  1. mod_rewrite - the problem with this approach is that it becomes a huge .htaccess file since we need to write a rule for each category.

RewriteMap指令 - 这次来到pretty的接近,因为我可以查询到建立映射文件输出数据库。不过,我后来才知道,我们没有获得的httpd.conf。

RewriteMap - this came pretty close since I could query the database to build map file for output. However, I've since learned we don't have access to httpd.conf.

的index.php - 我已经尝试通过我们这工作index.php文件运行一切,但不保存在浏览器友好的搜索引擎优化目的的网址

index.php - I've tried running everything through our index.php file which works, but doesn't keep the URL in the browser friendly for SEO purposes.

我希望有人有另外一种想法可能的帮助,我真的AP preciate它。如果你已经有了一个参考的东西在网络上,这将有助于这将会是巨大的。

I'm hoping somebody has another idea which might help, I'd really appreciate it. If you've got a reference to something on the web that would help that'd be great too.

推荐答案

为什么不来路由所有请求与mod_rewrite的的index.php文件,并使用PHP编写路由逻辑,这似乎这样更可靠的方式比写不同的重写规则?

Why not to route all requests to the index.php with mod_rewrite and use PHP to write the routing logic, which seems way more reliable way than writing distinct rewrite rules?

这么简单的.htaccess这一个

As simple .htaccess as this one

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

和在index.php几行PHP code

And few lines of PHP code in the index.php

$client_name = strtok($_SERVER['HTTP_HOST'],".");
list ($cat,$subcat) = explode("/",trim($_GET['request'],"/"));

这篇关于使用PHP SEO友好的URL来动态URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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