【问题标题】:How to make dynamic pages seo friendly url using htaccess如何使用 htaccess 制作动态页面 seo 友好的 url
【发布时间】:2013-12-31 21:42:36
【问题描述】:

在我的 php 页面中,我将链接设为 href="test.php?category="xyz"。 在 url 中,我希望此页面链接显示为“test/xyz”。

在我添加的 .htaccess 文件中

RewriteRule ^test/([a-zA-Z]+) test.php?category=$

但这对我不起作用。

test.php 中的所有其他链接都将 test 附加到它们的链接上。 例如。如果有 example.php,它会显示为 test/example.php

感谢您的帮助。 提前致谢

【问题讨论】:

  • 发布您的完整 .htaccess 代码。
  • 这是我的 .htaccess 文件 RewriteBase 上的 RewriteEngine /mysite RewriteRule ^(.*)\.html $1\.php 选项 +FollowSymLinks RewriteRule ^test/([a-zA -Z]+) test.php?category=$1 ErrorDocument 404 mysite.com/page_not_found.php

标签: php html .htaccess seo rewrite


【解决方案1】:

也许这段代码可以帮助你

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^test/([a-zA-Z]+)$ test.php?category=$1
</IfModule>

尝试访问这些网址:test.php?category=abctest/abc。如果两个页面显示相同的内容,则此代码成功。
要了解更多信息,请阅读reference here

【讨论】:

    【解决方案2】:

    这听起来更像是您忘记了在链接中使用完整的相对路径。而不是使用:

    <a href="example.php">example</a>
    

    你应该使用:

    <a href="/example.php">example</a>
    

    否则当您在页面/test/abcd 时,转到example.php 表示/test/example.php

    【讨论】:

    • 我在标签中给出了 php 页面中的完整链接 示例
    • 很好,但其他链接是什么? (即问题最后几行中的 example.php)
    • 进入 test.php 后,此文件中的所有链接都会在文件前面附加“test”。例如。如果在 test.php 中有 enquiry.php 文件,它将转到 test/enquiry.php
    猜你喜欢
    • 2015-12-10
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 2013-04-28
    • 2011-05-29
    • 2013-01-22
    • 2014-04-09
    • 1970-01-01
    相关资源
    最近更新 更多