简体   繁体   中英

Wordpress: htaccess point folder to root directory?

  1. I have a domain: www.domain.com - not wordpress cms, install folder public_html in hosting.
  2. I have a website English and German version - use wordpress cms.
  3. I install wordpress cms in folder: public_html/en/
  4. Link follow: www.domain.com not wordpress cms. www.domain.com/en/ wordpress cms root (English default) www.domain.com/en/de wordpress German version.

=> How to run the German version with the link as follow: www.domain.com/de

I tried with the .htaccess in the public_html folder but not run:

 RewriteRule ^/de$ /en/index.php

Thank all!

This is not perfect solution because WP is in charge of the URLs.

So even if the following is working, the URLs that WP put on your Website are still /en/de and so the user will always be clicking on /en/de and get than redirected to /de

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^/?en/de(/.*)?$ /de$1 [R=301,L]

RewriteRule ^/?de(/.*)?$ /en/de$1 [L]

Update:

If this is not working than you still have the WP issue, because WP can't interpreter the URL right, therefor this could not be solved by htaccess itself.

Put the folowing code at your main root .htaccess file :

RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !\s/+de/ [NC]
RewriteRule ^en/de/(.*)$ de/$1 [R=302,L,NE]
RewriteRule ^de/(.*)$ en/de/$1 [L]

The code above will only remove en if request contains en/de externally and redirect it internally to same path .

Test it , if it is ok , change 302 to 301 to get permanent redirection .

Note: clear your browser cache and test it .

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