问题
I will have a single-page website that will have URLs in the form of /en/my-page-here
and /ro/my-page-here
. The problem is that the rewrite rules make my http://localhost/ro/home
redirect to http://localhost/home
. If I am right then what can I do to correct these default lines in my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
in a way that does not stop working with a WordPress upgrade (the .htaccess contains, besides the lines above, a warning to not edit the file manually).
I use the latest WordPress version, 5.4.1.
Through "a single-page website" I meant a website that is like a web application, it has a single entry point PHP file. The routing features are made with client JavaScript, with a client-side library (Sammy.js).
I tried this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteRule ^index\.php$ - [L]
RewriteRule /ro/(.+)/$ /index.php [L]
RewriteRule /en/(.+)/$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
but without success. The docs for mod_rewrite are pretty big (I think I would need about two days to understand them on my own).
Please help me.
Thank you.
Update
I have read the introduction into mod_rewrite and updated the question's title and added this section here.
The problem I see is that if I write into the address bar of the browser: http://localhost/ro/home it redirects me to http://localhost/home, but if I type the URL of an nonexistent page such as http://localhost/ro/zzz it does not redirect. So I think it is a feature of WordPress. With wget
I get the information that http://localhost/ro/home has been permanently moved to http://localhost/home: 301 Moved Permanently
. What can I do to change this WordPress behavior in a custom theme?
I already did the REST APIs which get the article which has a custom field ID set to a string used by both versions of the article.
If an admin sees my update, I do not know if this question is in its best place, because I also have an account here.
Thank you.
来源:https://stackoverflow.com/questions/62102828/how-to-make-wordpress-use-these-urls-for-a-bilingual-single-page-website-en-my