简体   繁体   English

mod_rewrite使用或不使用Slash重写URL

[英]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 写出.htacess的正确方法是什么,以便www.domain.com/about_us和www.domain.com/about_us/访问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 选项+ FollowSymLinks
RewriteEngine on RewriteEngine on
RewriteRule ^(about)$ /about_us.php RewriteRule ^(about)$ /about_us.php
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). 之后/将进行/可选(0或1次出现)。 Also, the parenthesis are unnecessary: 此外,括号是不必要的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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