我正在尝试实现 301 重定向,以便我的所有 URL 都重定向到给定页面的 www 版本。我们的页面结构是:url.com/home/default.cfm。我正在尝试将 ColdFusion 中的 URL 重写为没有文件名的当前目录。
我正在使用的代码是这样的:
<cfif (CGI.SERVER_NAME NEQ "www.url.com")>
<!-- Save the URL (and $_GET variables too) as the string 'strUrl' -->
<!-- <cfset strUrl = CGI.script_name & "?" & CGI.query_string />-->
<cfset strUrl = CGI.script_name />
<!-- Use 301 for SEO-friendly redirects -->
<cfheader statuscode="301" statustext="Moved permanently">
<!-- Redirect to new website (this case, added www.) with strUrl added on -->
<cfheader name="Location" value="http://www.url.com#strUrl#">
</cfif>
这非常接近,除了 CGI.script_name 返回带有文件名的路径。任何想法如何获取目录?请记住,我们可能有嵌套目录,例如 /foo1/foo2/。
谢谢。