.htaccess exclude 301 redirect bypass pseudo static exception folder directory rule

WordPress Websites are deployed in Apache using .htaccess files to specify rewrite rules.

However, sometimes when there are other programs such as:CWP custom subdomain folder directory path Edit vhosts file, you need to exclude the 301 redirect exception folder directory, bypassing WordPress's pseudo-static rules.

The following is one possible approach.

.htaccess file to add exclude folder directory rule 

.htaccess exclude 301 redirect bypass pseudo static exception folder directory rule

If there isWill automatically jump to the second-level domain name without the www top-level domain name, you need to add a redirection exclusion folder directory rule in the .htaccess file ▼

RewriteCond %{REQUEST_URI} !^/img.chenweiliang.com/.*$ [NC]

Put this code before the first rule to achieve the specified directory exclusion function ▼

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/img.chenweiliang.com/.*$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  • After the setting takes effect, access the folder directory /img.chenweiliang.com/ Pages within the WordPress will not be processed by WordPress.

The secondary directory /go/ cannot be redirected

Chen WeiliangBlog useWordPress pluginFor the paid version of GTranslate, make sure that the GTranslate plugin does not use /go/ as the second-level directory and second-level domain name.

Found using Pretty Link plugin to add redirectsChen Weiliangblog'sTelegramWhen channel linking:
https://www.chenweiliang.com/go/tgchannel

  • (This is because the jump link of the Pretty Link plugin is overwritten by the RewriteRule redirection rule in the .htaccess file)

It will automatically jump to a subdomain that does not exist:
http://go. chenweiliang.com/go/tgchannel

  • (To avoid dead links, add a space after go. in the link above)

However, inChen WeiliangSearching in the .htaccess file of the blog did not find the RewriteRule containing /go/.

After I tried to remove the GTranslate config RewriteRule, this link redirected successfully:
https://www.chenweiliang.com/go/tgchannel

  • So, I'm pretty sure that the GTranslate config RewriteRule is causing the redirection error for the subdirectory link /go/.

How to exclude /go/ subdirectory redirection?

if neededSettingTo exclude multiple different subdirectories, you can refer to the redirection rules below to add them▼

RewriteCond %{REQUEST_URI} !^/?(directory1|directory2)($|/)
  • On directory1|directory2|etc put the desired number of directories in the .
  • This should be "if REQUEST_URI does not start with /directory1 or /directory2".

it will match:

  • /directory1/dasdas
  • /directory1
  • /directory1/

and many more……

How to set exclude /go/ jump links in RewriteRule?

Just add the following "exclude /go/ subdirectory redirection" rule to the top of the GTranslate redirection rule▼

# Exclude /go/ subdirectory redirection
RewriteCond %{REQUEST_URI} !^/?(go)($|/)

### BEGIN GTranslate config ###
RewriteRule ^([a-z]{2}|af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$ http://$1.chenweiliang.com/$2 [R=301,L,QSA]

RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$ /$1/$3 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$ /wp-content/plugins/gtranslate/url_addon/gtranslate.php?glang=$1&gurl=$2 [L,QSA]
RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)$ /$1/ [R=301,L]
### END GTranslate config ###

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared ".htaccess exclude 301 redirect bypass pseudo-static exception folder directory rules", helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-28236.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top