RedirectMatch query string issue - apache

I am moving content on a previous website where 2 copies of the site were made to translate it so that i only have one remaining.
To provide fallback access, i wrote this rewritematch rule :
RedirectMatch 301 /(en|fr)/(.+)\.php\??(.+)? /$2.php?locale=$1&$3
But it doesn't seem to be working.
If i do the following instead, everything works fine but i lose the query string passed in the original link which i really want.
RedirectMatch 301 /(en|fr)/(.+)\.php /$2.php?locale=$1&$3
Is there something i am doing wrong? Or are query strings not supported? (I checked but there seems to be no limitations on the apache docs).
Thanks in advance for your help!

try
RedirectMatch 301 /(en|fr)/(.+)(\.php\?)?(.+)?

Related

Redirect old articles to new articles .htaccess

This is a pretty specific question, so no answer on Stack or Google could help me.
Recently I've moved my blog from www.example.com to www.example.com/blog.
On www.example.com I have a landing page, so I need it to be working as well.
I would like to redirect all www.example.com/YYYY/MM/DD/article-name to www.example.com/blog/YYYY/MM/DD/article-name, but at the same time to keep www.example.com intact.
Thank you in advance for your help.
Try this code :)
RedirectMatch "^/(\d){4}/(\d){2}/(\d){2}/(.+)" "^/blog/$1/$2/$3/$4"
If this doesn't do the job, the following line definitely will:
RedirectMatch "^/(\d)+/(\d)+/(\d)+/(.+)" "^/blog/$1/$2/$3/$4"
Solved with Regular Expression inspired from the above answer from Hello Fishy(Thank you)
RedirectMatch ^/(\d*)/(\d*)/(\d*)/([A-Za-z0-9-]*)/ /blog/$1/$2/$3/$4

Issue with .htaccess redirects

I am trying to run a bunch of 301 redirects using an .htaccess file. However my rules are not working. I'm not sure what I'm doing wrong.
Here is my rules:
RedirectMatch 301 /directory/1 http://www.example.org/newdirectory
RedirectMatch 301 /anotherdirectory/2/3 http://www.example.org/newdirectory
If I visit www.example.org/directory I get redirected to the correct place. However if I visit www.example.org/directory/1 I do not get redirected. It seems to only work when there is just 1 level if I try to add more levels it stops working
Is there an issue with using "/" in the match? Should I try a regex expression instead of the actual path?
Please anyone can shed some light on this?

Apache rewrite url help, add string in the middle of the url

I need some help with my apache rewrites since I am quite bad at it.
I want to make an apache rewrite rule where I can rewrite links from my old site format to the new one.
http://foo.bar/old/$1 to http://foo.bar/new/$1. This should also work when old is a random string or empty.
Thanks in advance.
If anyone has the same issue as i did, i found the solution:
RedirectMatch 301 ^/([-0-9a-zA-Z])/(.)$ http://foo.bar/new/$2

Trying to redirect anything after the full URL without /68 for example

I need to remove anything on the end of URLs like the below examples without the /68 or any number ID
https://www.website.com/forum/making-coffee/68 <-- I would like to remove the / and anything after so it looks like this below.
https://www.website.com/forum/making-coffee
I've searched but can't get the redirect to work correctly.
Any idea?
You can use this rule in your root .htaccess
RedirectMatch 301 ^/(.+?)/[0-9]+$ /$1

Redirect Match. Remove Numbers from Url

Just in need of some assistance with some redirects.
I have the following url I need to remove the ending number from:
http://www.testsite.com/category/subactegory/this-product-name-12966.html
So it becomes:
http://www.testsite.com/category/subactegory/this-product-name.html
I have tried the following but cant quite crack it.
RedirectMatch 301 ^-([0-9]+).html http://www.testsite.com/$1.html
Any help would be greatly appreciated
Brendan
Actually your regex is little incorrect. Try this:
RedirectMatch 301 ^/(.+?)-([0-9]+)\.html$ /$1.html