开发者

SEO Friendly URL to Dynamic URL using PHP

Currently I have a url like this

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

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

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

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 - the problem with this approach is that it becomes a huge .htaccess file since we need to write a rule for each category.

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

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

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.


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?

As simple .htaccess as this one

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

And few lines of PHP code in the index.php

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


In addition to Col. Shrapnel's answer, at least slim the selection down:

RewriteRule ^/([-a-zA-Z0-9_]+)/([0-9]+)$ index.php?function_name=$1&cat=$2 [L,QSA]  # domain.com/cat_name/23 is sent to the server as domain.com/index.php?function_name=cat_name&cat=23
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜