2013-04-04 55 views
1

我想要两个国防部重写。让我解释。多ModRewrite - .htaccess


- 我需要一个重写,如果没有文件存在或目录存在,重定向到一个用户页面。 | 我已经这样做了。 - 接下来,我想从.php文件中删除扩展名。

我已经完成了第一次,我只是无法弄清楚我将如何做第二次?


我已代码:

RewriteEngine On 


RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 

RewriteRule ^(.*)$ users.php?name=$1 [QSA,L] 

所以我需要什么,我只需要删除PHP扩展,并保持当前重写工作。

+0

我认为你必须没做什么。只是不要在请求中包含php扩展,你的规则已经将不存在的所有内容重定向到'users.php'。如果您需要根据请求中的参数映射资源,请举例说明。 – 2013-04-04 13:55:45

回答

1

这应该是你的完整的.htaccess:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

## To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.*?)/?$ $1.php [L] 

## redirect to a userpage 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ users.php?name=$1 [QSA,L] 
+0

非常感谢工作! :D – 2013-04-04 15:26:42

+0

不客气,很高兴知道它解决了。 – anubhava 2013-04-04 15:34:27

0

删除.php扩展名:

RewriteEngine On 
# turn on the mod_rewrite engine 

RewriteCond %{REQUEST_FILENAME}.php -f 
# IF the request filename with .php extension is a file which exists 
RewriteCond %{REQUEST_URI} !/$ 
# AND the request is not for a directory 
RewriteRule (.*) $1\.php [L] 
# redirect to the php script with the requested filename 

只是点:

http://www.mysite.com/index

+0

对不起,我以为我更清楚。我需要两个,不只是删除.php扩展名。 – 2013-04-04 01:43:34

+0

如果您愿意在上市前试用.htaccess文件。我发现一个有用的文档是:http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html这应该清除任何其他问题 – 2013-04-04 01:47:25

+0

好吧,看起来不错。谢谢。 – 2013-04-04 01:48:05