.htaccess Rewrite ไดเรกทอรีย่อยของ Wordpress โดยไม่ทำลายไดเรกทอรีย่อยอื่น ๆ
ดังนั้นฉันจึงติดตั้ง WordPress ไว้/wp/
แต่ฉันต้องการให้ URL ของ WordPress ทั้งหมดถูกเขียนใหม่เพื่อให้ปรากฏในไดเรกทอรีราก ขณะนี้ฉันใช้งานได้แล้ว (ดูด้านล่าง) แต่ฉันต้องการเปลี่ยน.htaccess
เพื่อไม่ให้ทำลายไดเรกทอรีย่อยอื่น ๆ
ตัวอย่างเช่นหากฉันต้องการเยี่ยมชมwww.example.com/images/image.png
ปัจจุบันมันเปลี่ยนเส้นทางฉันไปที่หน้า 404 บน WordPress
เป็นไปได้ด้วย.htaccess
เหรอ?
รหัสปัจจุบัน:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
อัปเดต : ทดสอบคำแนะนำของ MrWhite ด้วยโหมดไม่ระบุตัวตนและเบราว์เซอร์ที่สอง ไม่มีผลอะไร. .htaccess
ไฟล์ใหม่:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
คำตอบ
คุณต้องเพิ่มเงื่อนไขเพื่อยกเว้นไฟล์ที่มีอยู่มิฉะนั้นคำขอ/images/image.png
จะถูกเขียนใหม่/wp/images/image.png
และทริกเกอร์ 404 ใน WordPress (เว้นแต่/wp/images/image.png
จะมีอยู่จริง)
ตัวอย่างเช่นเพิ่มเงื่อนไขต่อไปนี้ในกฎที่มีอยู่ของคุณ:
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
อัปเดต:ดูเหมือนจะไม่ได้ผล ยังคงไปที่หน้า WordPress 404
คุณวางRewriteCond
คำสั่งผิดที่
RewriteCond
คำสั่งไม่ใช่ข้อความที่แยกจากกันโดยสิ้นเชิง แต่เป็นเงื่อนไขที่ใช้กับRewriteRule
คำสั่งที่ตามมา ด้วยตัวเองRewriteCond
คำสั่งไม่ทำอะไร
RewriteCond
ความต้องการสั่งไป (ที่ใดก็ได้) ก่อนที่จะRewriteRule
สั่ง:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
นอกจากนี้ให้ดู.htaccess
ไฟล์"WordPress" ใน/wp
ไดเรกทอรีย่อยเพื่อใช้อ้างอิง นั่นก็เหมือนกัน
นอกเหนือ:เว้นแต่คุณจะมีหลายโดเมนหรือโดเมนย่อยที่คุณไม่ต้องการเขียนใหม่คุณสามารถลบการตรวจสอบชื่อโฮสต์ (เช่นRewriteCond
คำสั่งที่ตรวจสอบกับHTTP_HOST
ตัวแปรของเซิร์ฟเวอร์)