简体   繁体   中英

Handle links via mod_rewrite

I would like to short my URLs via mod_rewrite .

There are two types of URL on my website: One time with parameter and without parameters.

  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

I would like to call the sites like:

  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

This is what I have write right now…

eg

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

How is it possible as to do it on the right way?

You can use these 2 generic rules in site root .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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM