简体   繁体   中英

mod_rewrite rule specific to page

I have the following page structures:

  1. domain.com/page.php?cat=hello&url=world
  2. domain.com/careers.php?cat=careers&url=careers
  3. domain.com/article.php?cat=blog&url=this-blog-name

I would like them to work as follows:

  1. domain.com/hello/world.html
  2. domain.com/careers/careers.html
  3. domain.com/blog/this-blog-name.html

I tried the following without success (mod_rewrite is enabled and confirmed working):

RewriteRule ^([^/]*)/([^/]*)\.html$ /careers.php?cat=$1&url=$2 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /page.php?cat=$1&url=$2 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /article.php?cat=$1&url=$2 [L]

Your regular expressions are the same, so, Apache will fall in the first one each time.

Your could use the first part of URL to redirect to the known pages (careers, blog), then your expression for all others:

RewriteRule ^careers/([^/]*)\.html$ /careers.php?cat=careers&url=$1 [L]
RewriteRule ^blog/([^/]*)\.html$ /article.php?cat=blog&url=$1 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /page.php?cat=$1&url=$2 [L]

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