.htaccess redirect except one subfolder - apache

I need following type redirection:
/store/something/namestore to /store/namestore
However there is one exception:
/store/namestore/page/2 should not redirect to anything.
/store/namestore/page/3 should not redirect to anything. and so on.

If i understud the question right, this should be the solution.
RewriteEngine on
RewriteRule ^/store/([a-zA-Z0-9_\-]+)/([a-zA-Z0-9_\-]+)$ /store/$2/ [R]
or
RewriteEngine on
RewriteRule ^/store/([^/]+)/([^/]+)$ /store/$2/ [R]

Here is the solution in case someone else need:
RewriteCond %{REQUEST_URI} !^/stores/(.+)/page/.*$
RewriteRule stores/(.+)/(.+) stores/$2 [R=301,L]

Related

Rewrite one directory to another .htaccess

I want to automatically redirect http requests to news/images to ../images.
Is that possible with .htaccess?
Thing is: request to www.site.tld/news/images ... should go to www.site.tld/images ...
I have tried:
RewriteEngine On
...
...
RewriteRule (.*)news/images(.*) ../images [R=301,L]
not working.
I have ensured that apache have mod_rewrite.c enabled.
To redirect all requests for /news/images/ to /images/, capture the part after images and use it in the RewriteRule
RewriteRule ^news/images(.*)$ /images$1 [R,L]
When it works as it should, you may replace R with R=301. Never test with R=301.
You can use:
RewriteRule ^www\.site\.tld/news/images$ /www.site.tld/images?&%{QUERY_STRING}
or you can also use:
RewriteCond %{HTTP_HOST} ^www.site.tld/news/images$ [NC]
RewriteRule ^(.*)$ http://www.site.tld/images/$1 [R=301,L]
But as #arkascha said, please do some research first, there are MANY answers to this sort of problem! :) Either way, I hope this helps.

301 redirection in htaccess not working

I have and issue when I'm trying to redirect my old domain to my new domain. Things look like that right now:
newdomain.pl <- is connected to blogger account
olddomain.pl <- is connected to server with .htaccess file (before it was connected to blogger account)
I would like it to work like that : olddomain.pl/subdomain -> redirect to newdomain.pl/subdomain. But whatever I try to put into my .htaccess file it's redirecting my old site to main page of newdomain (newdomain.pl). I've tried codess like that:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^newdomain.pl[nc]
RewriteRule ^(.*)$ http://www.newdomain.pl/$1 [r=301,nc]
but it's also redirecting to main page of new domain. Only when I put:
RedirectRule / http://www.newdomain.pl
It's redirecting to http://www.newdomain.plsubdomain <- but there is slash "/" missing between the newdomain name and subdomain. Unfortunately when I write this:
RedirectRule / http://www.newdomain.pl/
it's redirecting to main domain page http://www.newdomain.pl, so it's not working. I don't know what can be wrong, I'm fighting with that three days already. Does anyone have an idea where can be the problem? Maybe there is something wrong with hosting that I bought? Thank you in advance for any response
Regards, Pawel
Try next:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R]
For only redirecting queries without direct redirecting to domain remove R flag.
Try this in olddomain/.htaccess :
RedirectMatch ^/(.*)$ http://newdomain.com/$1
Ok I found a solution. The problem was not including "www" in RewriteRule. When I changed it, it worked. I'm putting the code that worked for me below:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.pl$
RewriteRule ^(.*)$ http://www.newdomain.pl/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^olddomain.pl$
RewriteRule ^(.*)$ http://www.newdomain.pl/$1 [L,R=301]
Thank you everyone!

Where is my mod rewrite fail?

I have got url
ipaddr/opensys/base/
and some other similar, like
ipaddr/opensys/base/something.php?olol=yep
I want to remove from url "opensys" and display there "center", i want to see this links working:
ipaddr/center/base/
and
ipaddr/center/base/something.php?olol=yep
I did it with symlinks, but it was not good, because system is very difficult and with symlink some plugins not works, I want to do it with .htaccess only, after it all will be ok.
My htaccess is:
but links, which i want to see is not working, why?
RewriteEngine on
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [L]
RedirectMatch 301 ^/opensys/base/(.*)$ /center/base/$1
Redirect works good, but i see 404, rewrite rules is not working. Why?
You also need to handle the /center/base/ now in the .htaccess file as you must be handling opensys earlier. Something like this -
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [R=301]
RewriteRule ^/center/base/(.*)$ /index.php?args=$1 [QSA,L]
You can use this code in root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /opensys/(base/\S*)\s [NC]
RewriteRule ^ /center/%1 [R=301,L,NE]
RewriteRule ^center/(base/.*)$ opensys/$1 [L,NC]

htaccess RewriteRule for folder

I have a bunch of rewrite rules I would like to implement. I would like to redirect anything that has /blog/tag/... to my root url.
For example, all of these:
blog/tag/button-sets/
blog/tag/icons/
blog/tag/order-now/
blog/tag/body-attributes/
Would simply route to: www.url.com
I can do it on a case-by-case basis like below, but would like to redirect a bunch with 1 rule. Any help would be greatly appreciated
RewriteCond %{HTTP_HOST} ^url\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.url\.com$
RewriteRule ^blog\/tag\/button\-sets\/?(.*)$ "http\:\/\/www\.url\.com\/$1" [R=301,L]
Why dont you just remove the button-sets part of your rule like so
RewriteRule ^blog\/tag\/?(.*)$ "http\:\/\/www\.url\.com\/" [R=301,L]
Havent tested it but should be OK?
In stead make it such that it captures everything after the second / after blog/tag/(ANYTHING)/(CAPTURE) which will redirect to www.url.com/CAPTURE
RewriteRule ^blog\/tag\/.*\/?(.*)$ "http\:\/\/www\.url\.com\/$1" [R=301,L]

Redirect %20%E2%80%8E

I have this customer that send an email with http://url/%20%E2%80%8E and everyone is getting a 404 not found. So he asked me for a redirection and I though sure easy. But it looks like is not working... please help!!
I tried this:
redirect 301 /\%20\%E2\%80\%8E http://url/promo-content/
and
redirect 301 /%20%E2%80%8E http://url/promo-content/
and is not working..
I also tried this
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)/\%20\%E2\%80\%8E$
RewriteRule ^(.*) http://url/promo-content/%1/ [R,L]
But still not working... any sugestion???
The URI gets decoded first before mod_rewrite rules are applied. Try:
RewriteEngine On
RewriteRule ^\ ‎ /promo-content/ [L,R=301]