【问题标题】:htaccess rewrite without extensionhtaccess 重写不带扩展名
【发布时间】:2014-01-12 20:41:23
【问题描述】:

我是使用 htaccess 的初学者,但我不知道如何做我想做的事。我想了解我在做什么,所以如果你能帮我为ver(非常!)初学者提供一些建议,我将非常感激...... :) 我想: 将 xxx.php、xxx.html 或任何扩展名重定向到 xxx(不带扩展名) 现在,我的 htaccess 是

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

它可以工作,但只要我写 xxx。但是如果我写 xxx.php(我看到页面 :(,我想重定向到 xxx)并且如果我写 xxx.html 它什么也没有显示。

最后。我想将变量重写为友好链接 即如果我有 xxx.php?id=1 > 我想重定向到 xxx/username

提前谢谢你 最美好的祝愿和圣诞快乐! :)

【问题讨论】:

    标签: .htaccess mod-rewrite redirect seo friendly-url


    【解决方案1】:

    尝试将这些规则添加到您的 htaccess 文件中:

    RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php
    RewriteRule ^ /%1 [L,R=301]
    

    如果您需要对.html 扩展执行相同操作,则将该条件的php 部分更改为(php|html?)

    【讨论】:

    • 谢谢!有效! ;) 1 name > value 我想获取 id 的值并将其放入 URL... 抱歉,我对 htaccess 的了解几乎为零:/ 再次感谢
    【解决方案2】:

    试试这个:

    I use this code already.
    
    Rule:
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^([^\.]+)$ $1.php [NC,L]
    </IfModule>
    
    Put this in your htaccess file && then check for files without extension.
    

    谢谢

    【讨论】:

    • 您的代码使页面无需扩展即可打开,但它不会将 about.php 重定向到 about,这是 OP 要求的
    猜你喜欢
    • 2014-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多