Article directory
When a WordPress website is deployed in Apache, a .htaccess file is used to specify rewrite rules.
However, sometimes when other programs are running, such as CWP custom subdomain folder directory paths edit the vhosts file , it is necessary to exclude 301 redirect exception folder directories to bypass WordPress's pseudo-static rules.
The following is one possible approach.
.htaccess file to add exclude folder directory rule

If you want to automatically redirect users to a subdomain without the www top-level domain , you need to add a redirection rule to the .htaccess file to exclude specific folder directories. ▼
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 Weiliang's blog uses the paid version of the WordPress plugin GTranslate, and it has been confirmed that the GTranslate plugin does not use /go/ as a subdirectory or subdomain.
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, a search of Chen Weiliang 's blog's .htaccess file did not find a 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 you need to exclude multiple different subdirectories, you can refer to the redirection rules below to add them ▼
RewriteCond %{REQUEST_URI} !^/?(directory1|directory2)($|/)- On
directory1|directory2|etcput 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 ###Hopefully, the article "Excluding 301 Redirects and Bypassing Pseudo-Static Exception Folder Directory Rules" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-28236.html
