简体   繁体   中英

redirecting specific page using htaccess

I want to redirect like http://example.com/sites-related-to-australia-0.html .
In this "australia" and "0" are parameters. How can i do this using htaccess? i'm using php.

Any help greatly appreciated, Thanks!

It would likely be something like this:

RewriteRule ^sites-related-to-(\w+)-(\d+)\.html$ /somewhere_else.php?place=$1&pos=$2 [L]
  • /sites-related-to- will be the first part of the URL
  • The next piece (a block of one or more word characters signified by (\w+) (you can also replace this with a more specific (australia|united kingdom|france))) is captured for later as $1
  • The piece after the next hyphen will be captured as a digit (\d) and it will be stored as $2
  • Load the page somewhere_else.php with get variables place=$1 and pos = $2 (both defined earlier).
  • [L] means that this is the last redirect rule which effects this particular pattern.
RewriteRule ^sites-related-to-(\w+)-(\d+).html/$ sites-related-to.html?country=$1&val=$2 [L]
RedirectMatch sites-related-to-([^-]+)-(\d+)\.html$ http://www.anotherserver.com/something.php?country=$1&id=$2

Untested, see RedirectMatch .

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