【问题标题】:Apache .htaccess URL RewritingApache .htaccess URL 重写
【发布时间】:2013-03-06 09:50:14
【问题描述】:

我想更改一个网址:

http://opportunityfinance.net/industry/industry_locator_proc.asp?organization={组织名称}

这样的:

http://opportunityfinance.net/industry/{组织名称}

同时仍在访问第一个网址。 {ORGANIZATION NAME} 可以等于一堆不同的名称,实际上是任何名称。

必须有一种简单的方法来使用 .htaccess 文件执行此操作吗?

或者如果我们把它改成这样会更好:

http://opportunityfinance.net/organization={组织名称}

我认为哪个更容易对我有用。 谢谢,这里的你们太棒了!

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    您必须首先将带有RewriteCondredirect 的查询字符串部分捕获到新URL 的客户端

    RewriteEngine on
    RewriteCond %{ENV:REDIRECT_SEO} !1
    RewriteCond %{QUERY_STRING} organization=(.+)
    RewriteRule ^/?industry/industry_locator_proc.asp /industry/%1? [R,L]
    

    现在客户端请求新的 URL,而您从现有的 ASP 提供请求

    RewriteCond %{REQUEST_URI} !industry_locator_proc.asp
    RewriteRule ^/?industry/(.*) /industry/industry_locator_proc.asp?organization=$1 [E=SEO:1,L]
    

    环境设置E=SEO:1 防止死循环。

    当一切正常时,您可以将R 替换为R=301

    【讨论】:

    • 我很困惑。这一切都应该在 1 个 .htaccess 文件中吗?还是我们在这里谈论 2 个 .htaccess 文件?
    • @SolomonClosson 这进入一个 .htaccess 文件。
    • 好的,这根本不起作用。我有它在站点根目录,我应该把它放在industry 目录中吗?为什么industry 前面有一个??你有它:/?industry
    • @SolomonClosson 不,这应该在根目录中。我在我的环境中对此进行了测试,它重定向得很好。究竟发生了什么,“根本不起作用”是什么意思?
    • @SolomonClosson 也可以使用/industry/.htaccess 执行此操作,但必须稍作修改。
    猜你喜欢
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    相关资源
    最近更新 更多