为分类广告网站上的每个类别创建子文件夹

时间:2013-03-04 09:18:53

标签: php wordpress web categories subdirectory

我正在创建一个分类广告网站。

该网站具有按位置过滤的搜索功能。

目前我只是使用php GET函数通过url发送位置并在搜索数据库之前检索它。

我希望能够将该位置作为域的子文件夹。

是否可以在不上传每个位置的物理子文件夹和index.php文件的情况下使用?

请告知实现这一目标的最佳方案。

2 个答案:

答案 0 :(得分:0)

是的,这是可能的。 试试apache mod_rewrite:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

将其打开,并在.htaccess文件中(必须与index.php位于同一文件夹中):

RewriteEngine on

RewriteBase / # or the subfolder where your index.php is inside the domain
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?location=$1

index.php的一个例子:

<?php 
   print $_GET['location']; 
?>

这可能对你有所帮助。

答案 1 :(得分:0)

感谢您的帮助Kovge。

在回答并做进一步研究之后,我创造了一个完全符合我要求的RewriteRule。

由于位置处于一个结构中,有多个层次(对于State,Area,City,Suburb等),我已经做到了这一点,无论URL有多少个子文件夹,返回只会是最后的子文件夹(没有尾部斜杠)。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*/)?(.*[^/])/?$ /index.php?location=$2
相关问题