URL rewriting with WordPress - wordpress

I have WordPress running on Apache, I have some URL like this one:
https://www.mywebsite.com/fr/?type=Manager
And I want it to be :
https://www.mywebsite.com/fr/manager/
I tried different things such as:
RewriteRule ^?type=Manager$ manager/
but it's not working. With this one for example I'm getting a 500 error, and sometimes it just does nothing. I don't know if it's my htaccess config, or because it's WordPress or because I'm stupid.

Use this rule in your .htaccess instead:
RewriteRule ^fr/([^/]*)$ /fr/?type=$1 [L]
Make sure you clear your cache before testing this.

Related

Redirect one image to webpage Issue

I hope everyone is well.
I am having a few issues trying to redirect an image that was linked in error from an email to a html page.
For example the email points here - https://www.caravanguard.co.uk/news/wp-content/uploads/2021/03/Swift-Vogue-580-1.jpeg
But should point here - https://www.caravanguard.co.uk/news/make-mine-a-dealer-special-caravan-25644/
I have appplied the following to our .htaccess, but it does not appear to have worked. I have also done the same in the wordpress yoast plugin we use.
redirect 301 /news/wp-content/uploads/2021/03/Swift-Vogue-580-1.jpeg /news/make-mine-a-dealer-special-caravan-25644/
Any ideas?
With your shown samples, could you please try following. Please make sure to place these rules at top of your .htaccess file. Also please do clear your browser cache before testing any URLs.
RewriteEngine ON
RewriteRule ^news/wp-content/uploads/2021/03/Swift-Vogue-580-1\.jpeg/?$ /news/make-mine-a-dealer-special-caravan-25644/ [R=301,NC,L]
You can use a RewriteRule
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/news/wp-content/uploads/2021/03/Swift-Vogue-580-1.jpeg$
RewriteRule ^.+$ /news/make-mine-a-dealer-special-caravan-25644/ [R=301]
Make sure this rule is at the top of your htaccess or before your WordPress rules.
Had to remove the image from wordpress before it would allow the redirect to work. WP rules seem to have got in the way. The .htaccess rule I originally created then kicked in.
I tried the above comments prior to the deletion and they did not work. Cheers for your help both.

Get data from one url by using custom url pattern wp

Can anybody suggest me this-
example.com/topic/a-1.html using this url i want to get data from
example.com/topic?page=a&number=1 in wp.
I tried wp rewrite functions but that could not helped me.
& I tried this too.
RewriteEngine On
RewriteRule ^([^/])/([^/]).html$ /topic?page=$1&num=$2 [L]
Thanks for your reply.
If you set permalinks in options, all links in your site will have the form site.com/page, but if you need delivery get parameter you can do it anyway, adding at the end of the get request site.com/page?id=1&page=2
Well finally i got this rule.
i was missing index.php thats why wp was redirecting to 404.
RewriteRule ^topic/([^/])/([^/])$ index.php/topic?page=$1&num=$2 [L]
Finally it worked for me. :)

How to properly configure DNS and Flexible SSL for Wordpress hosted on OpenShift through CloudFlare

TL;DR: I want to redirect https to http on all pages except for admin/login, where I want the exact opposite to happen. I also want www redirected to bare domain name. (UPDATE: Check Update 3 for the answer)
As is probably clear from the title, I have a Wordpress blog hosted on OpenShift for free. I have a custom domain bought from GoDaddy. I'm using cloudflare so I can have free SSL.
Here's my configuration:
CloudFlare DNS:
CloudFlare Page Rules:
This is what worked best. I actually wanted to have this rule:
*ghostlessmachine.com/* -> https://ghostlessmachine.com/$1
But I ran into even more problems like that, even though it seems to be pretty much what I'm supposed to do according to this CloudFlare article. Actually, initially I wanted to only force SSL in admin pages, but I didn't even know how to attempt that. I thought of using two page rules, like this:
*ghostlessmachine.com/* -> http://ghostlessmachine.com/$2
*ghostlessmachine.com/wp-* -> http://ghostlessmachine.com/$2
But I had no luck.
Here's my OpenShift configuration:
When I write ghostlessmachine.com in my address bar, it correctly takes me to https:.... I have shared a link, however (https://ghost...), and one person has reported not being able to access it. I couldn't reproduce locally.
When I try www.ghost..., I get:
This webpage has a redirect loop
ERR_TOO_MANY_REDIRECTS
Does anybody have any idea what I'm doing wrong? I've lost track of how many different configurations I've tried, but nothing seems to work.
Thanks!
UPDATE
OK, so following the advice in the comment I managed to get the situation a bit better. Still it's counter intuitive for me how the article I initially linked to just didn't get the job done while the other SO question did. So here's what I've changed:
Deleted the www.ghost... alias from OpenShift.
Changed CloudFlare's CNAME record from www -> blabla.rhcloud.com to www -> ghostlessmachine.com
Created this Page Rule: www.ghostlessmachine.com/* -> http://ghostlessmachine.com/$1
Now both ghost... and www.ghost... work and take me to http://ghost.... However, if I type https://ghost..., it also works without redirecting me to simple http. This is a problem.
I tried using this Page Rule instead:
ghostlessmachine.com/ -> http://ghostlessmachine.com/$2
So that I got https://, http://www, www, everything redirected to http://ghost..., but it doesn't work. I can't access my blog anymore and whatever address I try I get ERR_TOO_MANY_REDIRECTS.
UPDATE 2
Here's my full setup after all suggestions:
htaccess:
wp-config.php:
CloufFlare:
Result:
https -> http on non-admin/login pages: WORKING ✓
Trying to access admin/login pages: ERR_TOO_MANY_REDIRECTS
Update 3
This did the trick:
I still don't understand why this works and the rest doesn't though. This was basically a series of rather blind trial and error with some input from Allen here and Simon in the CloudFlare support page. In any case, all my requirements are respected now, thanks!
make sure following in your wp-config.php file:
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
look over here: Force non-WWW but force https across all of wordpress & the entire domain
for redirect everything else to non-https, you can add following into your root .htaccess file, before the wordpress rewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/wp-admin.*
RewriteCond %{REQUEST_URI} !^/wp-login.*
RewriteCond %{HTTP_REFERER} !^https://.*
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Update:
CloudFlare's Page rule has following "Page rule priority is determined by their position in the list. If multiple rules match a URL, rules at the top take higher priority. "
let's see what happens before:
request to https://www.ghostlessmachine.com/wp-admin hit the first
rule, match found, then it goes to
http://www.ghostlessmachine.com/wp-admin!
now here comes http://www.ghostlessmachine.com/wp-admin, first rule,
no rewrite, goes down to 3rd rule, oops, it needs goto
https://www.ghostlessmachine.com/wp-admin!
this is how the loop comes

.htaccess redirect URL last part to same URL query strings value?

In my wordpress site I need do do below redirect.
http://www.mydomain.com/magazine-landing/lon-mayf/ to the http://www.mydomain.com/magazine-landing/?code=lon-mayf
Here lon-mayf can be anything.
I've tried below code in .htaccess file after # END WordPress but it is not work.
RewriteEngine On
RewriteRule ^magazine-landing/*$ www.mydomain.com/magazine-landing/?magcode=$1 [R=301,L]
How could I do this redirect?
Thanks.
RewriteRule's are executed in the order they appear. The rule for wordpress matches all requests, so it will never reach your rule. Besides that, your rule doesn't really do what you describe it should do.
Place this rule above the wordpress rule and below RewriteEngine on:
RewriteRule ^magazine-landing/([^/]+)/?$ /magazine-landing/?code=$1 [QSA,R,L]
Replace the R flag with R=301 after you are done with testing to make it permanent. Testing with permanent redirects can have unexpected outcomes due to caching.

mod_rewrite redirect for site that contains drupal

I am new to using mod_rewrite, so I need an explanation in simple terms. I'm trying to do a redirect for a directory that is in the same directory as a Drupal installation but is not part of Drupal.
For example, a file used to exist at http://mysite.com/events/listen/song.mp3. I rearranged so that the file now resides at http://mysite.com/listen/song.mp3.
I can use the following in mod_rewrite and it works:
RewriteRule ^events/listen/(.+)$ listen/$1 [NC]
However, I'd like to do a real redirect, so that the user sees the new URL instead of the old one. I've tried:
RewriteRule ^events/listen/(.+)$ listen/$1 [R,NC]
and
RewriteRule ^events/listen/(.+)$ http://mysite.com/listen/$1 [R,NC]
Neither of these work. I think it probably has to do with all the rerouting that Drupal is doing, though I do have my rewrite rules before Drupal's in .htaccess. Is there something obvious I'm missing? Or is there a way to allow this to work without messing up what Drupal is doing?
Try
RewriteRule ^events/listen/(.+)$ listen/$1 [R=301,L]

Resources