2016-06-09 107 views
1

我想通過mod_rewrite來縮短我的網址。
通過mod_rewrite處理鏈接

我的網站上有兩種類型的網址:一次帶參數且沒有參數。

  1. example.com/devel/pages/event.php?event=MYEVENTNAME
  2. example.com/devel/pages/image.php?event=MYEVENTNAME
  3. example.com/devel/pages /location.php?name=MYLOCATION
  4. example.com/devel/pages/home.php
  5. example.com/devel/pages/news.php

我想打電話給網站,如:

  1. example.com/devel/events/MYEVENTNAME
  2. example.com/devel/images/MYEVENTNAME
  3. example.com/devel/locations/MYLOCATION
  4. example.com/devel/home
  5. example.com/devel/news

這就是我現在所擁有的寫的...

RewriteRule devel/images/(.*)?$ devel/pages/images.php?event=$1 

如何才能以正確的方式做到這一點?

+0

有什麼理由不使用這個規則的工作? – anubhava

+0

使用此規則,第一個URL正在工作(devel/events/MYEVENTNAME)。我可以爲較短的網址添加規則嗎(另外)? Like:RewriteRule devel /(.*)?$ devel/pages/$ 1.php? – DanEpp

回答

2

您可以使用網站根目錄的.htaccess這兩個通用的規則:

RewriteEngine On 

RewriteRule ^devel/([\w-]+)/([\w-]+)/?$ devel/pages/$1.php?event=$2 [L,QSA,NC] 

RewriteRule ^devel/([\w-]+)/?$ devel/pages/$1.php [L,NC]