redirect with htaccess - apache

i need to redirect temporally a domain to a subdomain, this is my code for .htaccess:
Redirect 302 / http://m.domain.com/
this works great, but i have some subdirectories like: http://domain.com/photos, the code above redirects this way: http://m.domain.com/photos
i have a lot of subdirs and sub-subdirs, how i can redirect successfully all the subdirs to the same subdomain? (http://m.domain.com/)

Check out this post, I think it might help you. It looks like all you'd need to do is change your redirect to look something like:
Redirect 302 ^/.+/.*$ http://m.domain.com/
.htaccess redirect loop! All subdirectories to root

Hey, this is a tool for generating the redirect code, and lets you choose how the final URL looks, without knowing regex. Might help you.

Related

htaccess redirection implied html extension not working

I've tried many things before coming here, it should be a simple problem, but there is something I miss for sure.
I want to redirect a bunch of URLs to another ones, one by one, and here is an example in my .htaccess file :
RewriteEngine On
Redirect 301 /index.php/Microcontrôleurs_Généralités https://newdomain.org/Microcontrôleurs_Généralités
The thing is that the old URLs are files in a real folder "index.php" but with ".html" extension.
When I go to https://olddomain.org/Microcontrôleurs_Généralités, apache serves me the implied .html file. I can go to https://olddomain.org/Microcontrôleurs_Généralités.html too, it's the same file on disk.
But my redirection as above does not redirect anything.
If I add the .html extension to the file like this :
RewriteEngine On
Redirect 301 /index.php/Microcontrôleurs_Généralités.html https://newdomain.org/Microcontrôleurs_Généralités
Then, if I go to the URL with explicit ".html" at end, it is redirected correctly, but if I miss the .html, apache says the URL was not found.
I've turned this in my head numerous times, I can't figure out the real problem.
Help would be much apreciated, thx.

Htaccess Redirect with Regular Expressions

I have a question regarding htaccess configuration win a PHP Project
I have this code to use redirection
DirectoryIndex src/client/index.php
Redirect /app/about http://localhost/app/?p=about
Redirect /app/contact http://localhost/app/?p=contact
Inside src/client/index.php I check the GET[p] to include the page requested.
It works... but I dont want to modify the htaccess file each time I add a new page.
I would like to implement something like this but it doesnt work, Im pretty sure I have syntax errors
Redirect ^/app/(.*) http://localhost/app/?p=$1
Thanks for your time :)
You just need to use RedirectMatch:
RedirectMatch ^/app/(.*) http://localhost/app/?p=$1

Redirect “test/oldfile.htm” to “test/new.htm” using htaccess

I am Using XAMPP Server.
I have a folder or project named test in my htdocs.
I want to redirect user to redirect to newfile.htm when user access oldfile.htm direcly using htaccess.
I wrote below code in mine htaccess file but its not working
RewriteEngine on
Redirect 301 /oldfile.htm /newfile.htm
Kindly Guide me.
Redirect directive is part of apache alias module. You don't need to write RewriteEngine on to use Redirect. The reason why your Redirect failed is because you are a relative test path, you need to specify a full/absolute path in Redirect.
Redirect 301 /test/oldfile.html /test/newfile.html
should work. If the problem presists, Try clearing your browser cache and make sure you dont have other conflicting redirects in htaccess.

How to redirect a full directory to another webpage page?

So basically, I would like to know how to redirect all files within a directory to a page on my website. I would like to do this via my .htaccess file.
I have a directory, directory1, and it contacts many files.
I need to redirect all files within directory1 to www.mydomain.com/webpage.html
Is this possible?
You need to add this before any other rules in your htaccess file:
RewriteRule ^directory1/? http://www.mydomain/webpage.html [L,R=301]
Try using the 301 redirect first, it's the simplest and probably fastest method. Otherwise your solution will require mod_rewrite engine to be on.
Redirect 301 /directory1/(.*) http://www.mydomain/webpage.html
If that doesn't work try RedirectMatch, I haven't used either of these in a while myself so I'm just shooting from the hip by memory.
RedirectMatch 301 /directory1/(.*) http://www.mydomain/webpage.html

.htaccess 301 redirects for part of url

I am redesigning my website and in the process restructuring some of the linking structure.
To do the permanent redirects I am using the following code (.htaccess)
RedirectMatch permanent old-link($|\.html) http://thedomain.com/new-link.url
I am using a CMS and changing the link for a category changes the path of the url like so:
thedomain.com/old-category-link/old-article-url.html
to
thedomain.com/new-category-link/old-article-url.html
How should I code (.htaccess) the redirect of any URL that has
thedomain.com/old-category-link
(i.e
thedomain.com/old-category-link/old-article.html
thedomain.com/old-category-link/old-article-2.html
thedomain.com/old-category-link/old-article-999.html
)
to
thedomain.com/new-category-link/any-articles-old-url.html
Thank you
Not exactly sure what you are asking to be redirected to, but is it something like this?
RedirectMatch permanent old-category-link(.*) http://thedomain.com/new-category-link$1
This will make is so if someone requests:
http://thedomain.com/old-category-link they will get redirected to http://thedomain.com/new-category-link
http://thedomain.com/old-category-link/ they will get redirected to http://thedomain.com/new-category-link/
http://thedomain.com/old-category-link/article1.html they will get redirected to http://thedomain.com/new-category-link/article1.html
http://thedomain.com/old-category-link/article50.html they will get redirected to http://thedomain.com/new-category-link/article50.html
No answer worked for me. Here is what is working with my Wordpress site.
Example:
OLD URL: http://website.com/xxx/yyy/picture.png
NEW URL: http://website.com/wp-content/picture.png
So, I want to replace /xxx/yyy/ with the normal /wp-content/ path of WordPress.
Put this in your .htaccess file.
RewriteEngine on
RedirectMatch 301 /xxx/yyy/(.*) http://website.com/wp-content/$1