简体   繁体   中英

Apache .htaccess mod_rewrite multiple RewriteRules

I have migrated my site to a wordpress site and set up the permalinks to be the post name. I need to add a rewriteRule to take anything from a cgi directory and just send them to the home page Ive tried:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
RewriteRule ^cgi(.*)$ http://example.com

Removing the [L] from the wordpress rule and adding the last line but it still doesnt work. Can someone tell me what I'm doing wrong?

Keep L flag as before and your cgi rule should be placed below RewriteBase line:

RewriteEngine On
RewriteBase /

RewriteRule ^cgi(.*)$ / [L,NC,R]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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