【问题标题】:creating subfolders for every category on classifieds website为分类网站上的每个类别创建子文件夹
【发布时间】:2013-03-04 09:18:53
【问题描述】:

我正在创建分类网站。

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

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

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

如果不为每个位置上传物理子文件夹和 index.php 文件,这是否可行?

请就实现这一目标的最佳选择提出建议。

【问题讨论】:

标签: php wordpress web categories subdirectory


【解决方案1】:

是的,这是可能的。 试试 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']; 
?>

这可能会对你有所帮助。

【讨论】:

    【解决方案2】:

    感谢您对 Kovge 的帮助。

    在接受您的回答并进行进一步研究后,我创建了一个完全符合我要求的 RewriteRule。

    由于这些位置的结构具有多个级别(对于州、地区、城市、郊区等),我已经做到了,所以无论 URL 有多少子文件夹,返回只会是最后的子文件夹(不带斜杠)。

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

    【讨论】:

      猜你喜欢
      • 2012-05-08
      • 1970-01-01
      • 2014-09-30
      • 2017-03-30
      • 2012-03-24
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多