繁体   English   中英

htaccess-如何不基于URL模式重定向

[英]htaccess - how to not redirect based on url pattern

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# load index.php by default
DirectoryIndex index.php

RewriteBase /

# for all other requests load room.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!(index|room)\.php).+)$ room.php?u=$1 [L,NC]

我的htaccess当前将把任何人重定向到room.php如果该URL包含除根目录(例如http://www.example.com/anythingelse如果没有),它将直接直接指向index.php

但是我需要不能为特定的模式包括此重定向,以便可以在特定的文件夹中创建内容。 例如

http://www.example.com/1
http://www.example.com/2
http://www.example.com/3
http://www.example.com/4

这可能吗?

您可以在正则表达式模式中添加以下排除项:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# load index.php by default
DirectoryIndex index.php

RewriteBase /

# for all other requests load room.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(1|2|3|4)
RewriteRule ^((?!(index|room)\.php).+)$ room.php?u=$1 [L,NC]

暂无
暂无

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

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