【问题标题】:How to rewrite dynamic URL to SEO Friendly URL?如何将动态 URL 重写为 SEO 友好 URL?
【发布时间】:2011-12-08 08:33:05
【问题描述】:

我尝试了我在此站点中看到的所有内容,将动态 url 重写为 SEO 友好的 URL。

可能是因为我在 localhost 中使用它?

我试试这个,但也不起作用:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
RewriteRule ^index\.php/?(.*) /$1 [R,L]
RewriteCond $0 !^index\.php($|/)
RewriteRule .* index.php/$0 [L]

我还提到了一个在线动态 url 生成器,但它也不起作用。请帮忙。

我想重写这两个网址:

index.php?p=home
index.php?p=about me
index.php?p=contact me

【问题讨论】:

    标签: php apache


    【解决方案1】:

    你可以用这个:

    RewriteEngine on
    
    RewriteBase /
    
     # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?q=$1
    

    然后在您的 index.php 页面上,所有变量都将通过 $_GET['q'] 访问。如果你进一步使用 $location=array_filter(explode('/',$_GET['q']));那么 $location 将是一个包含每个目录的数组,因此 www.mysite.com/firstdir/seconddir/thirddir 将 $location[0] 作为 'firstdir' 和 $location[1] 作为 'seconddir' 等等。然后,您可以将这些与数据库中的 url_aliases 进行比较,以确定要显示的内容/模板。

    这对我来说也适用于 localhost,除了我将基本 url 部分从“/”更改为“/mycurrentconstructionsite/”

    希望有帮助!

    【讨论】:

    • 内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。请联系服务器管理员 admin@localhost 并告知他们错误发生的时间,以及您所做的任何可能导致错误的事情。服务器错误日志中可能会提供有关此错误的更多信息。
    • 你复制粘贴完全一样吗?如果您在根目录中,请确保保留 /,如果您想要不同的目录,请确保保留用户“/mydirectory/”...如果您使用的是 localhost/mytestsite(例如通过 xampp),那么请执行 codeRewriteBase /mytestsite /code 其余保持不变
    • 是的,先生,实际上我将 .htaccess 文件放在了我的 DynamiWebsite 文件夹中的所有 Web 文件中。
    猜你喜欢
    • 2012-12-29
    • 2018-07-01
    • 1970-01-01
    • 2012-09-06
    • 2021-07-06
    • 2010-12-24
    • 2015-07-30
    • 2012-02-28
    • 2015-10-23
    相关资源
    最近更新 更多