Redirect everything with permalink change
-
I am trying to redirect everything on the divorceecafe.com to divorceecafe.org. The former site uses /year/month/date/ in the URL but the new .org site does not. If I want all URLs like:
https://www.divorceecafe.com/2018/09/20/thankful-thursdays-the-unbroken/
to redirect to:
https://www.divorceecafe.org/thankful-thursdays-the-unbroken/
what parameters do I need to use and where do I enter them? Thanks for the guidance in advance.
Cemal
The page I need help with: [log in to see the link]
-
Until I find a way of doing this using the Redirection plugin, I added a couple of lines to the .htaccess file to handle the job. If you get the link redirect you, it is because of the changes in the htaccess file. I would still like to learn how to du it using the plugin though, it is gentler and kinder solution I think.
Cemal
hey, just an idea, you might want to try regular expressions.
This is your Current URL as regular expression. Make sure to use the ^ at the beginning.
^https:\/\/www\.divorceecafe\.com\/(\d{4}\/)(\d{2}\/)(\d{2}\/)(.*)Check the regular expression test using this link: https://regex101.com/r/vguaTC/1
Redirect to
https://www.divorceecafe.org/$4
You are using $4 because is the 4th capture group.This is the first 4 digits and the “/”
$1 = (\d{4}\/)The regular expresion below is repeated twice because it is the month and day.
$2 and $3 = (\d{2}\/)Lastly, it is the blog post
$4 = (.*)This is not tested but should work base on the instructions given on here https://redirection.me/support/redirect-regular-expressions/
-
This reply was modified 6 years, 3 months ago by
raymoncada1.
Thank you @raymoncada1, those are the expressions I used in the .htaccess file. However, I am not sure where to enter them in the plugin settings. Do I enter the entire line as the source URL and then the other as the destination or do the regular expressions go where parameters are entered? Any idea? I really would like to switch to using the plugin rather than the .htaccess if I can.
Thanks,
Cemal
In the redirect setting click the advanced gear and to the far right select regex from the dropdown.
Enter the source URL, including regular expressions, in the source URL field and the target in the target URL field. You will need to enable the regex option. You do not need to press the advanced gear icon.
https://redirection.me/support/redirect-regular-expressions/
I must be doing something incomplete. Although I copy and paste the lines from here to the fields, it does not work. I tried a couple of times and switched back to the .htaccess file redirect. When I have more time later, I may try once more.
For clarity, will the long regex line work for the links that do not have dates or do I need to create a second rule for that? Like:
^https:\/\/www\.divorceecafe\.com\/(.*)
https://www.divorceecafe.org\$1
Thank you both very much,
Cemal
You only need the path part, not the domain. $1 does not need to be escaped
@johnny5, do I understand that I need to enter for the source:
^/(\d{4}\/)(\d{2}\/)(\d{2}\/)(.*)
and for the destination:
https://www.divorceecafe.org/$4
Am I on the right track? If I do that, will the redirect handle URLs with no date, like:
http://www.divorceecafe.com/shop
or do I need to create a second redirect like:
^/\(.*)
for the source, and:
https://www.divorceecafe.org/$1
for the destination?
Thank you,
Cemal
The first pattern should work. You could remove the brackets, which capture data, for the date parts and just have the last part in brackets and then use
$1in the target. It doesn’t change anything but looks a bit simpler.The pattern will only match date based URLs.
If you add the second pattern it will also match date URLs, which is not what you want. You would need to make sure it has a lower priority (i.e. larger number) then the date redirect so it doesn’t match first.
@johnny5, brackets? Do you mean the parentheses? All of them?
^/\d4\/\d2\/\d2\/.*
https://www.divorceecafe.org/$1and
^/\.*
https://www.divorceecafe.org/$1Sorry for the repeated questions, this is not something I use everyday. If I write these incorrectly, could you please give me two pairs of lines, one with dates one without? I will copy and paste your lines into the fields.
Cemal
The round parentheses, yes. That captures information. You don’t need to capture the date information, so there is no need to surround it in round parentheses. You still need the curly brackets to indicate the number of digits.
^/\d{4}/\d{2}/\d{2}/(.*) => /$1
It is also not necessary to escape the slash /.
I was only referring to the first pattern you put, not the second.
You can use https://regex101.com/ to test regular expressions
Thank you, @johnny5 I will try these. My eyes are not that good and I did not differentiate the curly brackets and the parentheses and used the latter on all. That might have been a part of the problem too. I will use the magnifier to make sure I am reading them correctly. So, my source line was altogether wrong.
I will experiment and let you know. I appreciate your help and expertise.
Cemal
No dice! When I test the redirect, I am getting
expected
https://www.divorceecafe.org/$1
found:
https://www.divorceecafe.com/%5E/d%7B4%7D/d%7B2%7D/d%7B2%7D/(.*I think I will leave the htaccess file handling the redirect, it works for the URLs with or without dates in them. I know they are the equivalent but I must be doing something wrong in the plugin fields.
Thank you for your help in any case,
Cemal
-
This reply was modified 6 years, 3 months ago by
acekin.
What are the exact settings you’ve used? Can you post a screenshot? It does not look like you enabled the regex option.
Thank you for following up, I will try later today and offer screen captures. I appreciate your willingness to help to make this work. Stay tuned…
Cemal
-
This reply was modified 6 years, 3 months ago by
The topic ‘Redirect everything with permalink change’ is closed to new replies.