簡體   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