.htaccess - htaccess 无扩展名重写

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

我是使用 htaccess 的初学者,我不知道如何做我想做的事。我想了解我在做什么,所以如果您能帮我给我一些建议(非常!)初学者,我将不胜感激... :) 我想: 将 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

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

最佳答案

试试这个:

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.

谢谢

关于.htaccess - htaccess 无扩展名重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20763701/

相关文章:

apache - 使用 .htaccess 通过 index.php 重新路由所有请求,除了特定的一组请求

windows - 为什么 Windows 上的 localhost 上的 mod_rewrite 和 .htaccess 配置不起作用?

.htaccess - htaccess mod_rewrite 排除图像/css

c# - ASP.Net MVC - 有条件的未经授权的重定向

javascript - 转换表单获取php中的方法url

.htaccess 将所有页面重定向到一页

apache - .htaccess - 通用规则

.htaccess - htaccess 中的变量,RewriteRule 问题

javascript - document.location 如果页面具有特定值的类

php - 如何使用 PHP 创建错误 404 页面?