เปลี่ยนเส้นทางผ่าน htaccess โดยที่ IP ไม่ใช่ && ลบ index.php

ฉันมักจะใช้ไฟล์ htaccess นี้เพื่อลบ index.php ออกจาก URL ของฉันใน ExpressionEngine

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

AcceptPathInfo On

Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On

Options +FollowSymLinks

# Looks for files and directories that do not exist
# and provide the segments to the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>  

แม้ว่าวิธีนี้จะได้ผลดี แต่ก่อนที่เราจะย้ายไซต์นี้ไปสู่การใช้งานจริง เรากำลังเปลี่ยนเส้นทางการรับส่งข้อมูลทั้งหมดไปยัง URL ที่ระบุไปยังอีกไซต์หนึ่งผ่านไฟล์ htaccess นี้

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]

ที่อยู่ IP ของฉันกำลังแทนที่การเรียก localhost เพื่อให้ฉันสามารถเข้าถึงไซต์ได้

โดยพื้นฐานแล้วสิ่งที่ฉันกำลังมองหาคือการรวมกันของ 2 อย่างนี้ที่จะลบ index.php ออกจาก URL ของฉันให้ฉัน แต่ยังคงเปลี่ยนเส้นทางคนอื่น ๆ

ขอบคุณสตีเว่น


person Steven Grant    schedule 18.11.2012    source แหล่งที่มา
comment
ไม่แน่ใจว่าคุณต้องการอะไร แต่คุณบอกว่าคุณต้องรวมทั้งสองอย่างเข้าด้วยกัน แล้วทำไมคุณไม่เพิ่มเงื่อนไข REMOTE_ADDR ให้กับการเขียนใหม่ข้างต้นล่ะ ฉันขาดอะไรบางอย่างไปหรือเปล่า?   -  person Kamil Šrot    schedule 18.11.2012
comment
นั่นคือสิ่งที่ฉันพยายามที่ ฉันเพิ่มกฎ {REMOTE_ADDR} หลังกฎปกติของฉัน แต่ถึงแม้จะเพิ่มที่อยู่ IP แล้ว ฉันก็ยังถูกเปลี่ยนเส้นทางอยู่เสมอ   -  person Steven Grant    schedule 19.11.2012


คำตอบ (1)


พบว่าสิ่งนี้ใช้งานได้ดี:

RewriteEngine on

# If your IP address matches any of these - then dont re-write
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1 
RewriteRule ^(.*)$ http://www.anothersite.com/ [R=302,L]


# do not rewrite links to the assets and theme files
RewriteCond $1 !^(assets|themes|images)

# do not rewrite for php files in the document root, robots.txt etc
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml)

# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
person Steven Grant    schedule 19.11.2012