【问题标题】:I am unable to change the URL Structure in My PHP Website我无法更改我的 PHP 网站中的 URL 结构
【发布时间】:2015-11-05 08:56:42
【问题描述】:

我已经创建了网站,我想更改它的 URL 结构。 例如。

http://www.haitibravo.com/market/detail.php?add_id=73

我想在没有 ?点赞

http://www.haitibravo.com/market/product/73

我如何显示这样的 URL。请帮我。我尝试了很多技术,但我失败了。

【问题讨论】:

  • 谷歌Apache Mod Rewrite examplesMod Rewrite SEO Friendly URLs
  • 很抱歉,我无法理解您所说的内容。可以举几个例子吗

标签: php .htaccess url


【解决方案1】:

制作一个 .htaccess 文件并将以下代码保存在其中。

RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?r=$1
RewriteRule ^([a-zA-Z0-9_-]+)/item/$ index.php?r=$1

【讨论】:

  • 我应该将这些行添加到 .htaccess 文件中吗?
  • 是的。如果您在本地服务器上运行它,还有一件事。然后在谷歌上搜索如何在您用于 localhost 的软件上运行 .htaccess。
  • 不不,我在我的网站上运行它
  • 在我的域中有 4 个目录。我应该在每个目录中添加文件吗?目录的意思。市场、杂志、搜索,每个目录都有不同的网站但域名相同..
  • 您可以将其保存在根文件夹中,并将子目录的规则也写入根文件夹的文件中。就像如果你有子目录 dmain.com/sub-directory 你可以在根文件中写规则 RewriteRule ^([a-zA-Z0-9_-]+) sub-directory/$ index.php?r=$1 RewriteRule ^([a-zA-Z0-9_-]+)子目录/item/$ index.php?r=$1
【解决方案2】:
RewriteEngine On 
/* this enables you to write urls in desired fashion */
RewriteRule ^([a-zA-Z0-9_-]+)$ detail.php?add_id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/product/$ detail.php?add_id=$1

/*Something like this should redirecto from detail.php?add_id=n to your desired url */
RewriteCond %{THE_REQUEST} /(?:detail\.php)?\?add_id=([^&\s]+) [NC]
RewriteRule ^ item/%1? [R=302,L,NE]

/* You may need to play with the above slightly... */

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多