.htaccess 使用htaccess从url中删除.php

.htaccess 使用htaccess从url中删除.php,.htaccess,.htaccess,我需要知道如何从目录索引文件中删除“.php” 我不想看到这个: http://www.domain.nl/wa.admin/index.php?login_msg=nopassword 我看到了很多帖子,但出于某种原因,它们对我不起作用 这是我的基本规则 RewriteRule ^admin[/]*$ /wa.admin [L] RewriteRule ^([^./]{2}[^.]*)$ /index.php?page=$1 [QSA,L] 我必须在内部做什么,因为它来自重定向? 我必须

我需要知道如何从目录索引文件中删除“.php”

我不想看到这个:

http://www.domain.nl/wa.admin/index.php?login_msg=nopassword
我看到了很多帖子,但出于某种原因,它们对我不起作用

这是我的基本规则

RewriteRule ^admin[/]*$ /wa.admin [L]

RewriteRule ^([^./]{2}[^.]*)$ /index.php?page=$1 [QSA,L]
我必须在内部做什么,因为它来自重定向? 我必须使用绝对url才能工作吗


谢谢,里奇。这应该适合你

RewriteBase /

# Stop rewrite process if the path points to a static file anyway
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .* - [L]

RewriteRule (.*) index.php
用文字解释:如果请求的资源是文件夹或文件,请不要重写,如果不重写,请重写到index.php

在您的情况下,
wa.admin/index.php?login\u msg=nopassword
将类似于
wa.admin/?login\u msg=nopassword

别忘了更新你的应用程序。此规则仅将请求映射到相应的文件。这不会影响HTML输出。这意味着通过这种重写,您可以访问两个URL,但要在应用程序中链接哪个URL取决于您自己

如果你想与其他人一起发布你的应用程序,你可以将环境与If标记结合使用来确定mod_rewrite是否可用

<IfModule mod_rewrite.c>
# Enable URL rewriting
RewriteEngine On

# Set flag so we know URL rewriting is available
SetEnv REWRITEURLS 1

# You will have to change the path in the following option if you
# experience problems while your installation is located in a subdirectory
# of the website root.
RewriteBase /

# Stop rewrite process if the path points to a static file anyway
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule .* - [L]

RewriteRule (.*) index.php

</IfModule>

这对我来说确实有用@Stoyno。我编辑了我的问题。我必须在我的“标题”重定向中使用绝对URL吗?@Richard如果你想重定向,你应该首先检查mod_rewrite是否被激活,然后你必须像这样使用绝对URL:
Header('Location:http://www.example.com/');谢谢,是的,我找到了,我会在分发应用程序的情况下进行检查。如果使用绝对URL有缺点的话,我会去谷歌。我能记得的唯一一件事是,它将花费额外的DNS查找。无论如何,我会记下你的答案。
<?php
$rewriteurls = apache_getenv("REWRITEURLS");

if ($rewriteurls == '1') {
    //adjust all your links
}
?>