2011-12-19 65 views
2

我想这样的URL重写:URL重写 - 在URL删除目录名称 - PHP

http://localhost/public/viewbusiness.php?s=cyberbooger-web-services

http://localhost/viewbusiness.php?s=cyberbooger-web-services

从而在网址中删除目录名。 您注意到viewBusiness.php位于public目录中。

我的应用程序没有遵循MVC架构,也没有使用框架。这是我正在学习PHP的一个应用程序。

我的文件夹结构是这样的:

- /应用

- /公共

- 的index.php

谁能帮助我?非常感谢!

+0

是你的PHP文件viewbuisness.php中的index.php文件夹存在呢?或者有公共文件夹的sym链接?因为一旦公众被删除将nt它扔404? – GoodSp33d 2011-12-19 04:55:25

+0

index.php位于根文件夹中,而vieBusiness.php位于公共文件夹中= root/public/viewBusiness.php – 2011-12-19 05:00:47

回答

0

尝试:

 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^(\w+)/(\w+)$ $1/public/$2 [QSA] 
</IfModule> 
+0

我需要在哪里保存该文件?在httpd.conf中?感谢 – 2011-12-19 05:01:48

+0

在你的.htaccess文件中 – 2011-12-19 05:03:14

+0

.htaccess必须保存到什么目录中?根或公共文件夹内? – 2011-12-19 05:06:59