【问题标题】:url rewrite using .htaccess to make friendly urls使用 .htaccess 重写 url 以制作友好的 url
【发布时间】:2015-07-24 09:22:22
【问题描述】:

我有 3 个关于 .htaccess 的问题,

1- 如果我使用 .htaccess 重写我网站上的 url,它是否会影响任何请求,或者我是否需要更改所有表单的链接,例如,如果表单的操作帖子是 index.php?submit我需要更改该链接吗?例如,当我在 .htaccess 中隐藏 .php 扩展名或者它不影响它时

2-我如何基本上隐藏所有 .php 扩展名

3- 如果我有以下网址

www.link.com/post.php?post_id=53&post_name=the-International-day-in-roma

a-)我如何让 .htaccess 将其重写为以下内容

www.link.com/post/the-International-day-in-roma

b-)如果有逗号有关系吗?或者我也可以删除它们吗?

www.link.com/post.php?post_id=53&post_name=everyday,-or-today,-or-tomorrow

【问题讨论】:

  • 每个线程一个问题
  • 你能回答我的第三个吗@anubhava
  • 抱歉,第 3 个要求很困难,因为 postId 53 不在原始 URL www.link.com/post/the-International-day-in-roma 中,因此无法重写为 www.link.com/post.php?post_id=53&post_name=the-International-day-in-roma
  • 那我需要做什么?删除 post_id=.. 然后我就可以重写了?如果是的话怎么办? @anubhava
  • post_id 将需要在 post.php 中进行查找。你可以有漂亮的 URL:www.link.com/post/53/the-International-day-in-roma

标签: php apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

希望这些答案可能会有所帮助:

(2) 我先回答第二个问题。在您的 .HTACCESS 文件中使用此代码删除 PHP 文件扩展名

 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^\.]+)$ $1.php [NC,L]

(1) 对于您的第一个问题........您可以从文件名中删除 PHP 扩展名。反正变化不大。在编写代码时,只需让您更轻松。

(3) 试试这个教程:

HTACCESS Tutorial

【讨论】:

    猜你喜欢
    • 2013-05-24
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2018-09-10
    • 1970-01-01
    • 2021-07-06
    相关资源
    最近更新 更多