1

我最近学习了使用.htaccess, 的 URL 重写。作为初学者,这对我来说已成为一项艰巨的任务:(

我可以重写一个特定的 url,比如:

RewriteEngine On
RewriteRule    ^nothing/?$    abc.php    [NC,L]

但我对此并不满意,需要你的帮助。

我的 .php 文件保存在一个名为files. 所以我有这样的网址:

www.mysite.com/files/login.php?lf=student
www.mysite.com/files/login.php?lf=admin
www.mysite.com/files/s_home.php
www.mysite.com/files/recharge.php

我想要的很简单:

mysite.com/login
mysite.com/login
mysite.com/s_home
mysite.com/recharge

有人可以帮忙吗?

4

2 回答 2

0

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

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

RewriteCond %{DOCUMENT_ROOT}/files/$1.php -f
RewriteRule ^([^/]+)/(.+)/?$ /files/$1.php?lf=$2 [L,QSA]

RewriteCond %{DOCUMENT_ROOT}/files/$1.php -f
RewriteRule ^([^/]+)/?$ /files/$1.php [L]
于 2013-02-27T16:07:34.167 回答
0
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

即使这会按照您的要求进行,但您为什么要尝试隐藏.php扩展程序?

于 2013-02-27T15:46:14.143 回答