【问题标题】:Mod_Rewrite on but doesn't change URL LayoutMod_Rewrite 打开但不更改 URL 布局
【发布时间】:2014-10-18 18:10:09
【问题描述】:

您好,我在通过 .htaccess 重写我的 URL 时遇到问题

PHP 信息: 服务器 API CGI/FastCGI 主机设置: Apache mod_rewrite 开启

当前网址布局:

http://www.xxxx.at/beitrag.php?thema=Bitcoins%20fuer%20jedermann%20gratis

通缉:

http://www.xxxx.at/beitrag/Bitcoins%20fuer%20jedermann%20gratis(可以 我可能也将 %20 更改为“-”?)

我已经创建了一个 .htacces,它看起来像:

RewriteEngine On
RewriteRule (.*)_(.*)\.html$ /bitcoins.php?to=$1 [qsappend,L]

但 URL 看起来还是一样,没有任何变化。

有人可以帮帮我吗? 问候

【问题讨论】:

    标签: php apache .htaccess url mod-rewrite


    【解决方案1】:

    试试:

    Options -Multiviews
    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+beitrag\.php\?thema=([^&\ ]+)
    RewriteRule ^ /beitrag/%1 [L,R]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^bietrag/(.+)$ /bietrag.php?thema=$1 [L]
    
    1. 关闭多视图,这样/beitrag 就不会被/beitrag.php 抢先服务
    2. 第一条规则匹配 HTTP 请求行,对查询字符串进行分组,并重定向浏览器,以便新 URL 显示在位置栏中
    3. 第二条规则匹配新 URL,并在内部将其重写为带有查询字符串的那个。

    【讨论】:

    • 请编辑您的答案以添加对您的代码如何工作以及它如何解决 OP 问题的解释。很多 SO 发帖人都是新手,看不懂你贴的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多