I'm using multisite WordPress and qTranslateX plugin. My default website is in Bahasa and my second language is English. When I use custom link in mode language English like mydomain.com/multisite, it always added by "en" after mydomain.com, it will be mydomain.com/en/multisite. That link always return 404 because there is no page.
I want to use .htaccess to rewrite URL form mydomain.com/en/multisite to mydomain.com/multisite/en .
Thanks in advance
Unfortunately, you can't achieve that with mod_rewrite alone as far as I know.
Wordpress will look at the REQUEST_URI to figure out what to show, and that one won't be overwritten (and [E=REQUEST_URI:...] will make it $_SERVER["REDIRECT_REDIRECT_REQUEST_URI"]).
If mod_proxy is installed as well, you could do something like this:
RewriteEngine On
RewriteBase /
RewriteRule ^en/([^/]+)(/?.*)$ /$1/en$2 [P,L]
It will proxy the request internally on the same host and server.
Requesting http://example.org/en/test will look to wordpress as if http://example.org/test/en was requested.
Give it a try. If mod_proxy isn't installed, it won't work (and render a 404 for the URL), but it won't break your site, so it's pretty safe to experiment with.
Related
I am using WordPress exclusively as a backoffice for my Next-js app.
I only need 3 endpoints:
https://mydomain/graphql/*
https://mydomain/wp-admin/*
https://mydomain/wp-content/*
I don't want to have anything else accessible. Is it somthing I should configure in the HTACCESS file or should I use a plugin?
You could potentially do something like the following at the top of your root .htaccess file to block all URLs, except for those that start /graphql/, /wp-admin/ or /wp-content/.
For example, try the following:
RewriteEngine On
RewriteRule !^(graphql|wp-admin|wp-content)/ - [F]
If anything else is requested then a 403 Forbidden is served.
However, I suspect there will be other URLs/files that still need to be accessible for this to work?
I have a really weird issue. My customer wants to have a website structure that ist like the following:
www.mydomain.com/myapplication/de/
www.mydomain.com/myapplication/at/
www.mydomain.com/myapplication/ch/
They have installed Wordpress to the /de/ folder.
Now they want to also reach the same wordpress-installation by going to /at/ and /ch/ but keeping this URL-Fomat.
so
www.mydomain.com/myapplication/de/a-wordpress-page.php
should also be reachable like:
www.mydomain.com/myapplication/at/a-wordpress-page.php
www.mydomain.com/myapplication/ch/a-wordpress-page.php
Unfortunately putting the wordpress-application to the maindomain is not an option, due to their weird system...
I hope is understandable.
Hope someone can help me.
It's easy.
You can redirect or rewrite your /myapplication/at/ and /myapplication/ch/ URL paths to the main /myapplication/de/ using a RewriteRule in htaccess.
RewriteEngine on
RewriteRule ^myapplication/(at|ch)/(.*)$ /myapplication/de/$2 [L,R]
Put this at the top of your WordPress htaccess file.
And change R to R=301 when you are sure the redirection is working perfectly fine.
If you want to keep the URL format then just remove the R flag from the rule. The rule with R will make an invisible redirection of URLs.
I have a rewrite question. It drives me crazy. I created a new website in worpdress. I want to redirect old urls (that are in google) to the new urls. That works fine except for the following urls (there is a plus in the old url)
www.domain.com/slugname/this+is+a+slug
Has to be rewritten to:
www.domain.com/slugname/this-is-a-slug
How to replace the plus for a dash (.htacces? add_rewrite_rule?)
Sombody has example code?
I tried .htacces an add_rewrite_rule in worpdress, but im not smart enough ;)
If you're happy to do it on an individual basis per URL then the following in your .htaccess file (it's important the file is spelt correctly) should work:
RewriteRule ^oldpage$ http://www.example.org/newpage? [R=301,L]
So your example might be:
RewriteRule ^slugname/this+is+a+slug$ http://www.example.org/slugname/this-is-a-slug? [R=301,L]
The R=301 part of the rule makes the redirect permanent, which I assume is the desired effect. Removing this would make the redirect a 302, which is known as temporary.
If you are looking to replace all + with - in the URL then you can use a generic statement:
RewriteRule ^(.*)+(.*)$ /$1-$2 [L,R=301]
There is a plugin in WordPress called Redirection, that will allow you to redirect old links to new links. It takes a lot of hassle from trying to do it in the .htaccess. You can use regex on the plugin.
Once installed the plugin can be found under the tools menu.
I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.
I have a Wordpress blog hosted on one server:
http://blog.example2.com/
And another site on a separate server:
http://www.example.com
Is it possible to get the blog to be served at the following URL?:
http://www.example.com/blog/
If so, I'd love to know how. I messed around with mod-rewrite, but it looks like it will only redirect (not rewrite) to another URL, in this case.
For those interested: I realize I could install the blog on the same server, but I'd rather keep things decoupled for now.
Many Thanks
You'll need to use mod_proxy:
ProxyPass /blog http://blog.example2.com/
ProxyPassReverse /blog http://blog.example2.com/
This'll need to be in server/vhost config. Otherwise, you can use it along with mod_rewrite in an htaccess file (in your document root):
RewriteRule ^/?blog/(.*)$ http://blog.example2.com/$1 [L,P]
ProxyPassReverse /blog http://blog.example2.com/
If you're using cookies in your blog, you'll need to make sure to correct the paths/domains.