Cant redirect folder exluding one subfolder - htaccess - .htaccess

I am having problems writing some redirect rules. I want all the pages inside the "/es" folder to be redirected to my homepage but excluding the pages in /es/empresa that need to redirect to mydomain.com/nosotros/. I have written this code but it is not working:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/es/empresa/($|/)
RewriteRule / http://www.example.com/ [R=301,L]

You can use these 2 redirect rules:
RewriteEngine On
RewriteRule ^es/empresa(/.*)?$ /nosotros$1 [R=301,NC,L]
RewriteRule ^es(/.*)?$ / [R=301,NC,L]

Related

301 redirection whole domain to new one + few individual pages to new urls

I have olddomain.com - and I want to redirect to newdomain.com with htaccess and 301 - thats easy and working very well for me - if I am redirecting whole domain.
But on the new domain I changed few urls (now they are different then on the previous domain) and I want to redirect whole domain and few specific pages to few specific pages and I dont know how to combine this 2 conditions (redirect whole domain and redirect few specific pages).
This is working for me
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ https://newdomain.com/$1 [R=301,L]
and I would like to add to the code some specific redirects like this but I dont know how to combine it together that it will be working:
Redirect 301 /something/ https://newdomain.com/something-changed-new/
Thank you in advance for a help.
Check this rewrites in top of your .htaccess file
RewriteEngine On
RewriteRule ^something\/$ https://newdomain.com/something-changed-new/ [R=301,L]
RewriteRule ^other\/$ https://newdomain.com/something-changed-other/ [R=301,L]
RewriteRule ^old\/$ https://newdomain.com/new/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule (.*) https://newdomain.com/$1 [L]

Redirecting to a different directory

I have a full site setup at mysite.com/2/
I want urls like:
mysite.com/about to redirect to mysite.com/2/about
mysite.com/work/photos to redirect to mysite.com/2/work/photos
I was hoping I could solve this and add the /2 after the domain through the htaccess file and not have to move the whole site up a level.
Try the folowing code if you want redirect
RewriteEngine On
RewriteCond %{REQUEST_URI} !(about|work/photos)/(2)
RewriteRule ^(about|work/photos)/(.*)$ /$1/2/$2 [R=301,L]
If you need only internal redirection change the last line with this :
RewriteRule ^(about|work/photos)/(.*)$ /$1/2/$2 [L]
If you want to change all requests :
RewriteEngine On
RewriteCond %{REQUEST_URI} !/(2)
RewriteRule ^(.*)/(.*)$ /$1/2/$2 [R=301,L]

Htaccess rewrite in subfolder with parameters

I'm trying to rewrite /streams/post.php?id=1 into /streams/thread/1 .
I did find some codes for .htaccess with parameters but it didn't work in the subfolder.
Also, should I put another .htaccess in the subfolder or use the one on the main directory? ( /.htaccess or /streams/.htaccess)
Also, in the past when I've rewritten, sometimes it redirects from for example /streams/thread/1 to /streams/post.php?id= and sometimes it actually displays /streams/thread/1 in the URL, I would like it to display /streams/thread/1 in the URL, not just redirect.
You can put your htaccess in root or streams folder (that's up to you).
In root folder
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . streams/thread/%1? [R=301,L]
RewriteRule ^streams/thread/([0-9]+)$ streams/post.php?id=$1 [L]
In streams folder
RewriteEngine On
RewriteBase /streams/
RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . thread/%1? [R=301,L]
RewriteRule ^thread/([0-9]+)$ post.php?id=$1 [L]

301 Redirects on old content with new cakephp site

I am updating an old asp site to cakephp - the old site has various listings on google based on the old "filename.asp" urls - I'd like to put Redirect 301s in the htaccess file to try and hang on to those search results (most of the pages have a complementing page on the new site), but something appears to be going wrong. htaccess as follows (excluding standard cake stuff). What am I doing wrong?
Redirect 301 contact.asp /contact
Redirect 301 portfolio.asp /portfolio-design-web
Redirect 301 webhosting.asp /
I've tried with the htaccess in the root directory, and webroot but it should just work wherever, no?
--
fixed it using mod_rewrite, following rules inside .htaccess on webroot work:
RewriteRule ^contact.asp$ /contactos/ [R=301,L]
Try modifying app/webroot/.htaccess like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^contact.asp$ /contact [R=301,L]
RewriteRule ^portfolio.asp$ /portfolio-design-web [R=301,L]
RewriteRule ^webhosting.asp$ / [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Redirect website root to subdirectory

How can I redirect all requests going to web root to another folder (e.g. public/)?
I've already tried this (contents of .htaccess in web root):
RewriteEngine on
RewriteRule ^(.*)$ public/$1
But now I have duplicate content for addresses:
address.tld/ and address.tld/public/
I would like to redirect address.tld/public/ to address.tld/, so there won't be any duplicates, but I just don't know how to do it and not get into redirecting cycle...
Try these rules:
RewriteCond %{THE_REQUEST} ^GET\ /public/
RewriteRule ^public/(.*) /$1 [L,R=301]
RewriteRule !^public/ public%{REQUEST_URI} [L]
With mod_rewrite you'll not get redirecting cycles.

Resources