0

我需要知道如何从目录索引文件中删除“.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]

我必须在内部做什么,因为它来自重定向?我必须使用绝对网址才能使其工作吗?

谢谢, 丰富

4

1 回答 1

1

这应该适合你。

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_msg=nopassword看起来像wa.admin/?login_msg=nopassword.

不要忘记更新您的应用程序。此规则仅将请求映射到适当的文件。这不会影响您的 HTML 输出。这意味着通过这种重写,您可以访问两个 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>

用于apache_getenv("REWRITEURLS");访问设置变量的值。

您的代码可能如下所示(未经测试):

<?php
$rewriteurls = apache_getenv("REWRITEURLS");

if ($rewriteurls == '1') {
    //adjust all your links
}
?>
于 2012-12-25T23:29:55.260 回答