Rewrite URL -> Subfolder rename --> htaccess - wordpress

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]

Related

Weird Domain handling for 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.

Redirect To A Custom Url Depending on Location on wordpress with parameters

I need to redirect my store customers to another clone installation in a sub-directory.
For Example:
A US visitor can visit: ‘example.com/product’
When a Canadian visitor visits the same link, it should redirect to: ‘example.com/ca/product’
I have tried out a few geo redirection plugins but the issue is as follows:
The redirection goes to ‘example.com/ca’ and the ‘product’ part is left out.
Any fixes?
NOTE: I have a clone installation of ‘example.com’ on ‘example.com/ca’.
I didn't need such a comprehensive multilingual plugin setup in my wordpress installation. So I have just used multi-site and added this to my htaccess file to redirect users to my 'irish' site based upon browser language config:
RewriteCond %{HTTP:Accept-Language} ^ie [NC]
RewriteCond %{REQUEST_URI} !ie [NC]
RewriteRule ^(.*)$ https://yoursite.com/ie [L,R=301]
I hope this is a quick and easy fix for someone. As I tried doing an action in functions.php and kept going around in circles for an hour!
You should use the plugin WPML for multilanguge. With this plugin you can use the option redirect by language WPML > Languages > Redirection according to browser language. I have it set up like this in a website of mine and it works fine.
If you want do it trought IP, you will need to add some more work. Im sending you info, I hope it is useful for you:
https://wpml.org/forums/topic/autoselect-native-language/#post-284007
http://wordpress.org/plugins/geographical-redirect/
https://wpml.org/forums/topic/how-to-detect-ip-location-and-automatically-display-local-language/

.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.

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.

How to rewrite URL in wordpress

I am facing some issue with url rewrite for wordpress
I have URL like this:
http://example.com/mentor-profile/?mentor_slug=dr-jonathan-fass
http://example.com/mentor-profile/?mentor_slug=neha
This is not user and SEO friendly, I want URL like this:
http://example.com/dr-jonathan-fass
http://example.com/neha
I am doing change in .htaccess file but something going wrong. Thanks.
Basically, Wordpress allows you to use SEO and user friendly URLs, just change your permalink settings in Administration area -> Settings -> Permalinks and set them to Post name.
More information - here.
You can use wordpress plugin to edit url whatever you want like below:
http://wordpress.org/plugins/custom-post-type-permalinks/
Or search another on the same site which suits to your requirement
The desired redirects could work for example like this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)&?mentor_slug=([^&]+)&?(.*)$ [NC]
RewriteRule ^/?(.*)$ /%2? [R=302,L]
Anyway, you should also define other cases, like:
Is it possible, that there are folders before the parameter? What should happen for example in the following case:
http://example.com/mentor-profile/test/asd/albala/?mentor_slug=dr-jonathan-fass
Should these folder be kept or be cut?
What should happen, if there are any other parameters, for example:
http://example.com/mentor-profile/?test=asd&ala=balab&mentor_slug=dr-jonathan-fass&hi=hello
Should other parameters be kept or be lost?

Resources