Redirect sub-folder to another folder - apache

I need to redirect the content of domain.com/app1 to domain.com/apps/app1, but keep the url domain.com/app1.
How to do that?
Is it possible to do via .htaccess file, or should I modify httpd.conf file, add some VirtualHost ...?
Thanks.

You can use this rule in http or virtual host config:
RewriteEngine On
RewriteRule ^/?app1(/.*)?$ /apps%{REQUEST_URI} [L,NC]
You may use this rule in site root .htaccess as well.

Related

Htaccess rewrite to file located up one level

I have an htaccess in a subdomain with the following rule:
RewriteEngine On
RewriteBase /
RewriteRule ^feed([0-9]+)$ ../image.php?id=$1 [L]
So basically I want to redirect requests from feed which is located in a subdomain to image.php file which is located in the main domain (just one directory above). Using ../ doesn't seem to work like in PHP.
So how can I rewrite to file in the parent directory?
Thanks!
You can use mod_alias for this. Add the following directive to .htaccess file of subdomain:
AliasMatch "^/feed([0-9]+)$" "/absolute/path/to/image.php?id=$1"
Alternatively you can use symbolic links, but in my opinion AliasMatch directive is better.

301 apache redirect non existing path using .htaccess joomla

I want to redirect a path: /folder/filename.html to: /folder/newfolder.
My host says I must create a dummy file at /folder/filename.html or it won't redirect. I can't do this as by creating the /folder, that messes up Joomla which would normally create that part of the path dynamically. I'm not sure I believe my host, surely it's possible to redirect a path regardless whether there is a file there?
In your .htaccess after RewriteEngine On just add this line
RewriteRule ^/folder/filename.html /folder/newfolder/filename.html [R=301,L]

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 configure site maintainance page

I am trying to configure in apache httpd.conf for the below scenario. Can anyone please advise how to do it.
When the apache instance is up and some one tries to hit below url
http://mydomain.com/xxx
It should display content exists in sitemaintenance.html without changing url context path.
Assume sitemaintenance.html resides in /usr/local/apache/my-apache-instance/htdocs/sitemaintenance.html
Here xxx is a subdomain which is hosted separately from main domain (mydomain.com).
-KS
Try placing this into httpd.conf or .htaccess for your sub-domain:
RewriteEngine on
RewriteCond /usr/local/apache/my-apache-instance/htdocs/sitemaintenance.html -f
RewriteRule ^.*$ /sitemaintenance.html [PT,L]
The condition in RewriteCond enables rewrite only if that file exists, so you can dynamically add or delete it, without re-starting Apache or changing .htaccess.

How can I rewrite this URL with Apache?

I want to be able to access sitenamehere.com/folder/index?a=something by visiting sitenamehere.com/folder/something in my address bar.
How can I do this?
I've looked into mod rewrite but I don't understand it.
mod_rewrite is an Apache (web server) extension not related to PHP. You'll want to create a file called .htaccess and include the following line:
RewriteEngine On
RewriteRule ^folder/(.*) /folder/index.php?a=$1
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Your .htaccess or httpd.conf.
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Your rule
RewriteRule ^([^/]+)/([^/]+)/?$ $1/index?a=$2 [L]
This assumes you want where folder is to be mapped over to where folder is in your example. If you want to match the literal folder, just replace the first capturing group with it (and add it to the replacement).