简体   繁体   中英

mod_rewrite URL rewriting with or without Slash

What is the correct way to write out the .htacess so that both www.domain.com/about_us and www.domain.com/about_us/ goes to www.domain.com/about_us.php

Currently, what I have is the below and just wonder if there's a way to put it in one line

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(about)$ /about_us.php
RewriteRule ^(about/)$ /about_us.php

It's a regular expression, so adding ? after the / will make the / optional (0 or 1 occurrences). Also, the parenthesis are unnecessary:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^about/?$ /about_us.php
RewriteRule ^about/?$ /about_us.php

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