Htaccess redirect or rewrite - apache

I'm in the process of testing a site at a preview URL until the DNS transfers over. I'm previewing the site at http://IP_ADDRESS/~name/.
All of my images that have been uploaded in the CMS are listed like <img src="/uploads/images/">.
But this doesn't work while i'm on the preview URL. So ideally I need to redirect /uploads/* to /~name/uploads/*
I was wondering if this should be a redirect or a rewrite in htaccess and what the rule might be?
Thanks.

This is the code you'll need in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^uploads/ ~name%{REQUEST_URI} [L,NC]

Related

htaccess URL rewrite is not working in production but works on local

I have a problem with URL rewritting and htaccess. I have an URL like www.example.com/index.php?fc=module&module=mymodule&controller=name&id=35 but it's too complex for people so I want to change it. I created a directory in my host like example.com/web/title-for-name/ where I put this .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?fc=module&module=mymodule&controller=name&id=35$1 [L,NC]
I've tested it in my local and it seems to work but when I test it in production it just redirect me changing my URL. Mod-rewrite is enabled because my web is rewriting other URLs. Also AllowOverride is set to All. The main difference between my local and production is that I'm not using Varnish.
I've solved this problem. There was an URL rewrite before mine that changed the domain .es to .com and changed the rest of my URL so I just changed the link I use to the .com domain.
Thanks everyone.

htaccess rule without noticable redirect

i have the following redirect rule
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^$ /folder/
basically my index.html file is in folder.html and instead of copy and pasting the index.html file from /folder/ i was trying to use the rule above to request the file and output the file as mysite.com but instead it is redirecting to mysite.com/folder/index.html. I assume this is possible to do as frameworks use the rewrite rule and this doesn't redirect the browser. Can anyone advise on what i am doing wrong?
Thanks in advance.

.htaccess is not rewriting my url

i'm quite new to .htaccess file and I nees a bit of help..
I have a Greek site and I want to have urls like επικοινωνία.html. However, I haven't managed to translate successfully using htaccess file.
My code, for example, is:
Options +FollowSymlinks
RewriteEngine On
RewriteRule επικοινωνία.html contact.html
However, the url showing in the browser is not changing at all.
What am I missing?
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^επικοινωνία\.html$ /contact.html [L,B,R]

How to redirect to subdomain but then allow normal use of site

So I have my site, www.domain.com.
For a week or so I want to direct all traffic going direct to the site to subdomain.domain.com, a little promo page about an upcoming feature. I want visitors to then be able to continue to the site as normal though after they've read it, so a continue to www.domain.com/index.php link.
How can I do that with in the htaccess file? Everything I've tried so far messes up when clicking the continue link.
Thanks
with .htaccess you could use a 302 temporary redirect, but it would be for a whole sub folder as far as I know.
Another way would be to redirect with JS/server site language to the subdomain, create a cookie, then redirect back to www.domain.com/index.php .
the 302 redirect is explained here: How do I redirect my site using a .htaccess file?
You would need to have a .htaccess for the root folder point to your subdomain
Note that this is only possible if you enable mod_proxy in the Apache config of domain.com otherwise URL will change after redirect.
Enable mod_proxy, mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^index\.php$ http://subdomain.domain.com/ [L,NC,P]

Apache redirects: do not redirect if URL contains

i have a situation where i want to prevent any redirects if the URL contains "akamai"
Basically, if URL contains akamai do not redirect.
Any ideas?
Your requirements are not very clear.
Try this code in your .htaccess file:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteRule ^(.+)(?<!akamai)$ /akamai-$1 [L,NC]
Negative lookbehind (?akamai.