Weird Domain handling for Wordpress - wordpress

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.

Related

.htaccess regex beginner redirection problem

I'm a beginner in redirecting with htaccess. I wanted to do a small redirect, but am already stuck.
My first redirect was:
RewriteRule ^/project/(.*) /search/?type=details&projectid=$1 [R=301,L]
Which works fine. The problem is, that if the link gets shared on facebook, the outbound link of facebook is added with a ?fbclid=XXX. So my links get turned into:
/search/?type=details&projectid=1?fbclid=XXX
So now I somehow have to find the "?fbclid=XXX" (in case there is one) and stick it behind a &. For now I have:
RewriteRule ^/project/([^/]*)/?(.*)$ /search/?type=details&projectid=$1&$2 [R=301,L]
But this only works if there is a / inbetween the projectid and ?fbclid.
Can anyone give me a clue, what I'm missing?
thank you very much.

.htaccess rewrite domain.com/en/multisite to domain.com/multisite/en

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.

Rewrite URL -> Subfolder rename --> htaccess

I am in need for some HTACCESS support here. I dont believe it is very complex if I read through all the comments on similar request but simply dont get it working on my side - even after rebuilding the Permalinks.
This is my situation: I use WordPress 4.2.2 and have a theme with a portfolio. The slug of this portfolio is /portfolio/ which I want to change to /examples/
Now I have a second slug for the categories of this portfolio /PORT_CAT/ which also need to be rewritten to /example-cat/
The url is like: http://wwww.domain.com/portfolio and http://www.domain.com/port_cat/
Can somebody support me with the URL rewrite state to add to my HTACCESS and if required additional steps to rebuild the structure properly so it reflects in the front-end/browser?
Thank you in advance for the support!
This should do it, but I'm not sure why you can't change the URI in Wordpress.
RewriteEngine on
RewriteRule ^examples/?$ /portfolio/ [QSA,NC,L]
RewriteRule ^example-cat/?$ /port_cat/ [QSA,NC,L]

Redirect slug, replace plus for dashes

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.

mod_rewrite does not trigger css to load

I want to redirect all requests to index.php and any %{REQUEST_URI} portion should be passed as an argument to index.php. Also, even if the %{REQUEST_URI} portion points to an existing file/directory, I still want to do the redirect. For example, there is a directory called js in my document root. When I access my site like http://www.example.com/js, then I still want to redirect to http://www.example.com/index.php?uri=js instead of displaying the content of the directory in a browser.
So, I added the following two lines in my .htaccess file.
RewriteEngine On
RewriteRule .* index.php?uri=%{REQUEST_URI} [QSA]
But this does not work.
First, when I specify a path to an existing file, e.g. http://www.example.com/foo.css, it still displays a content of the file in a browser. (What I want is http://www.example.com/index.php?uri=foo.css) Second, when accessing a directory, e.g. http://www.example.com/js, then the redirect happens, but css fails to take effect and my site looks corrupted.
The good news is it works fine if I specify an arbitrary string that does not point to any files/directories in the root. I spent hours trying to debug this, but I have no clue. How would I solve my problems?
FYI, I'm using Apache 2.4.3.
Maybe this following code :
RewriteEngine On
RewriteRule ^index.php?uri=(.*)$ $1 [L]
I don't know if it's that you want.

Resources