0

I have inherited a custom ColdFusion CMS app. The URL's that it creates are horrendous. Not at all suitable for SEO or readability for that matter. An example of a URL in this CMS is:

http://www.mysite.com/Index2.cfm?a=000003,000010,000019,001335

Basically, each level of hierarchy is stored in the database based upon that long string of comma separated values. So in the case of the example I used, that particular page is 4 levels deep in the CMS hierarchy.

Basically what I would like to see is a format similar to this

http://www.mysite.com/level-1/level-2/level-3/level-4

Is this possible? Any help would be greatly appreciated. For what it's worth we are using ColdFusion 6 at present time, but will be upgrading to 8 in the near future.

4

1 回答 1

1

首先,你愿意在 URL 中有 index.cfm 吗?喜欢:http ://www.mysite.com/index.cfm/level-1/level-2/level-3/level-4 ?如果没有,那么您需要进行重写以删除 index.cfm,但仍允许 CF 处理该页面。您的 .htaccess 看起来像这样:

RewriteEngine On

# If it's a real path, just serve it
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

# Redirect if no trailing slash
RewriteRule ^(.+[^/])$ $1/ [R=301,L]

# Rewrite URL paths
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^([a-zA-Z0-9/-]+)$ /index.cfm%{REQUEST_URI} [PT]

下一步,您需要“捕捉”这些 URL,并根据对 SEO 友好的 URL 提供正确的页面。您可以从 CGI.path_info 变量中获取传入的 URL。在不知道代码当前如何处理这些 URL 变量的情况下,很难知道您的代码应该是什么样子,但本质上,您将拥有某种映射函数来获取对 SEO 友好的名称并替换为数字以获取内容。

第三步是重写您的 CMS 生成的任何 URL,以输出对 SEO 友好的 URL。同样的映射在这里发生,只是相反。

于 2012-05-16T15:56:09.673 回答