URL重写使用htaccess跳过文件夹名称

时间:2014-02-05 06:38:25

标签: php apache .htaccess url mod-rewrite

我有一个列出教育中心的网站。我有两个疑问。

  1. 我有一个用于打印此类学院详情的网址

    www.example.com/education/eduS.php?Main=colleges&Name=nameOfCollege

  2. 我这样写了这个网址

    www.example.com/education/colleges/nameOfCollege
    

    我的htaccess是

    RewriteRule ^(.*)/(.*)$ eduS.php?Main=$1&Name=$2 [L,NC,QSA]  
    

    我的问题是

    • 我想从我的网址跳过文件夹名称eduaction,以便像这样获取网址

      www.example.com/colleges/nameOfCollege 怎么可能。我想将Main和Name作为GET参数。

    • 我的第二个问题是,我有另一个网址,用于在一个页面中列出大学名称。像这样的网址

      www.example.com/education/edu.php?Main=colleges&Category=Engineering-colleges 我像这样重写

      www.example.com/education/colleges/Engineering-colleges 我的htaccess

      RewriteRule ^(。)/(。)$ edu.php?Main = $ 1& Category = $ 2 [L,NC,QSA] 但这显示出一点混乱。以上两个URL具有相同数量的GET参数。我该如何处理这个问题。

    • 我还需要从第二个URL跳过相同的文件夹名称教育。任何人帮助我

1 个答案:

答案 0 :(得分:1)

DocumentRoot/.htaccess

中使用此代码
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ education/eduS.php?Main=$1&Name=$2 [L,QSA]

这样您就可以使用以下网址:/colleges/nameOfCollege