Rewrite double url issue - .htaccess

I have been trying several different combinations for resolving the following URL. I just can't get it to redirect where I need it to.
https://www.oldsite.com/http://www.oldsite.com/
needs to redirect to
https://www.newsite.com/
I can't find the right combination to work.
Any help is greatly appreciated.

Related

.htaccess redirect to another page while retaining the complete query string

I am a little lost. I tried searching this site and the web at large, but I couldn't seem to find exactly what I need. So please forgive me if this has been answered before, I really tried to find it.
I have … inherited a .htaccess file with quite a lot of 301 redirects in the
Redirect 301 /shorthand /actual-link/actual-file.php
syntax (with a RewriteEngine On line somewhere high up in the file). I don't know exactly much about redirects, but that seems pretty straightforward to me. It just sits there and sometimes new shorthand links get added. There is some non-www to www, and http to https kind of stuff at the top, that's it.
Now the structure of the site changes, and two similar pages that process query parameters get consolidated into one. Basically there is
Old page: /path/subpath/index.php?some=query&parameter=or&other
New page: /other-path/file.php?added=parameter&some=query&parameter=or&other
I can't predict what parameters exactly will be part of the URL, I just have to take everything starting from the ? and append it to the new URL, that already has to include an added parameter, so everything after the ? follows ?added=parameter& .
I suppose that is not exactly hard, but alas, I lack the experience. And all I could find was something like "Take this specific defined query parameter you already know and set it as a path name" or vice versa, and I couldn't get that to work for my problem.
Is there a solution compatible with the syntax used elsewhere in the file? Or does that matter at all? Can I combine Redirect 301 … lines with RewriteCond … RewriteRule … commands? Does %{QUERY_STRING} help me somehow? If so, how can I figure out the correct syntax?
I would really appreciate if someone could point me in the right direction.
Many thanks in advance!

How to redirect in htaccess with a wildcard

This is really bugging me, for something that should be real simple.
Trying to 301 redirect a URL (via htaccess) - in the following manner:
https://www.example.com/forums/sub-forum/index.php
needs to be redirected to:
https://www.example.com/forums/sub-forum/
Basically want to get rid of the index.php (note: the sub-forum is a wildcard, as it can be anything, e.g. football-forum or tennis-forum etc...)
So far I've managed to work out that I need to do something along these lines:
RedirectMatch 301 ^/forums/.*/index.php /forums/<wildcard>
However, I'm not sure what to put in instead of <wildcard> part. I've tried putting .*, but that doesn't work
Any ideas on how to achieve this? Your help would be much appreciated.
Many thanks.

using regex to escape folders in a 301 redirect

I've had a look at all kinds of online resources and can't quite work this out.
Would really appreciate a well explained answer so I can work this out and help others with it too!
I have this structure:
website.com/blog/year/month/day/blog-title/
and I need to create a 301 redirect removing the blog and date like so:
website.com/blog-title/
I've been trying all kinds of combinations of letters that I don't really understand without any luck.
Any pointers greatly appreciated,
Thanks!

Remove directories from URL using .htaccess

I've been searching around and tried many different ideas to fix the state of a URL for my client, but have had no joy.
The URL currently looks like this:
website.com/folder1/folder2/folder3/page.php
My client wants this to be showing much like the other links on the website as so:
website.com/page
I'm fine with removing the .php that's simple enough and is already written into my .htaccess file. It's just removing the 3 directories from the URL is what I cannot work out.
Before anyone asks about moving the file to a higher directory, I'm afraid this cannot be done as everything needs to be down in this 3rd directory for this page.
I believe my latest attempt is about the closest I've got to solving this, if anyone could point out my mistakes and a solution it would be much appreciated:
RewriteRule ^/folder1/folder2/folder3/(.*)$ /page$1 [L,R=301]
EDIT:
After researching more today, I think I may have confused people with this question. I think what I should have said is that I need to mask the URL, hiding the 3 directories, and showing just the domain and the page itself.
I still seem to be hitting a wall with masking too. Any advice?
After a whole weekend (and quite a bit of the week between working) I finally managed to succeed with what I wanted.
The site now displays as required:
website.com/page
Which has been redirected and masked from:
website.com/folder1/folder2/folder3/page.php
The piece of code required in the .htaccess is as follows:
RewriteRule ^page$ /folder1/folder2/folder3/page.php
Looks like I was being stupid before and had the syntax backwards, but all is well now and I'm allowed to sleep :)
Hope this helps anyone else in future with this sort of problem!

Is this possible with an htaccess rewrite

I am wondering if this is possible to do with an .htaccess rule.
My beginning url:
http://cmfi.org/wherewework/missionary/?missionary=ttaho%2C
What I want to end up with:
http://cmfi.org/wherewework/missionary/ttaho
The ttaho will change according to the page.
Thanks for any input.
Don't think I was asking anyone to code this for me...Just asking if it was possible. I have tried a few things and couldn't get them to work. The %2c is an encoded part of the url that is added from the plugin I was using.
I will figure it out. No worries.

Resources