Redirecting multiple domains to subdirectories with htaccess

I do not have root access to a server, and so I have been using an htaccess file to redirect multiple domains to various subdirectories so that I can host them as different websites, even though the DNS all points to the same location: --> /domain1/ --> /domain2/

and so forth, so that users who type "" into their browsers see content in the /domain1/ subdirectory, but in their browser location bar, it shows only "" and not "".

It works for the most part, but sometimes when clicking around or submitting a form within a website/domain, a user does occasionally end up seeing "" in their browser location bar.

I don't want that. I want anything at "" to always show as "" etc. I want subfolders such as "news" to show as "" and never as "".

I feel like there's a problem with my symlink directives in that they don't fully take. Here's my htaccess code:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain1\.com
RewriteRule ^(.*)$$1 [R=permanent,L]

RewriteCond %{HTTP_HOST} ^(ww+\.)?domain1\.com
RewriteCond %{REQUEST_URI} !/domain1/
RewriteRule ^(.*)$ /domain1/$1 [L]

# etc for each unique domain...

I'm hoping my syntax is off, or that there's another condition I can add to clarify things, making the domain subdirectories fully behave as root directories regarding internal links and forms, etc.

Any and all pointers appreciated. Thanks.

301 Redirect for All Subdirectories

I am changing domain names for a WordPress site and want to set up a structure like so:

If a user accesses, he will be re-directed to, etc. In other words, only the pre-slash part of the domain would change. I want to do this for all pages under the old domain.

So far, I have only been able to get to re-direct to, but not any of the sub-directories (for example, does not re-direct to Here is my .htaccess file:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^newdomain\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain\.com$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Does anyone know what I did wrong?

.htaccess help – Codeigniter

I currently have an .htaccess file to rewrite index.php out of all of the base URL's, example ->

The .htacces file is as follows in the root of my public_html folder:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|adminer|resources|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

As far as I know, this rewrites any /URL that isn't images, css, resources, etc.. to point toward index.php.

I am now trying to add to my .htaccess a rule to rewrite ->

With the current rules in place, I receive a 500 - Internal Server Error when I try to visit I have also tried the following to no avail:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|adminer|resources|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^/forums(.*)
RewriteRule ^forums(.*)$$1 [R=301,L]

How do I change these rules to allow the redirection of index.php and rewrite to

SSL on Apache doesn’t work when mod_security enabled

I setup a new SSL certificate on my Apache server, and now when I try to access my website from HTTPS I get the error message "403 Forbidden". From the apache log file I get:

[Fri Jul 31 20:54:51.069453 2015] [:error] [pid 12132] [client **.24.36.***] ModSecurity: Rule 7fdb76085a90 [id "981172"][file "/usr/share/modsecurity-crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"][line "157"] - Execution error - PCRE limits exceeded (-8): (null). [hostname ""] [uri "/test"] [unique_id "Vbggm6wfDPoAAC9k-CQBAAAB"]

This is the line 157 of the above file:

SecRule REQUEST_COOKIES|!REQUEST_COOKIES:/__utm/|!REQUEST_COOKIES:/__utm/|REQUEST_COOKIES_NAMES "([\~\!\@\#\$\%\^\&\*\(\)\-\+\=\{\}\[\]\|\:\;\"\'\´\’\‘\`\<\>].*?){8,}" "phase:2,t:none,t:urlDecodeUni,block,id:'981172',rev:'2',ver:'OWASP_CRS/2.2.8',maturity:'9',accuracy:'8',msg:'Restricted SQL Character Anomaly Detection Alert - Total # of special characters exceeded',capture,logdata:'Matched Data: %{TX.1} found within %{MATCHED_VAR_NAME}: %{MATCHED_VAR}',tag:'OWASP_CRS/WEB_ATTACK/SQL_INJECTION',setvar:tx.anomaly_score=+%{tx.warning_anomaly_score},setvar:tx.sql_injection_score=+1,setvar:'tx.msg=%{rule.msg}',setvar:tx.%{}-OWASP_CRS/WEB_ATTACK/RESTRICTED_SQLI_CHARS-%{matched_var_name}=%{tx.0}"

So I tried to disable mod_security and indeed after it works fine.

Since I need to keep mod_security enabled, how can I fix this problem?


I edit the file /usr/share/modsecurity-crs/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf and I delete the line 157, now it works but what about the risk?

redirecting an .htaccess with regular expression

There are SO many .htaccess redirect posts on here, but unfortunately none that match my situation that I can find, and I'm struggling with understanding regular expressions to make this work. My situation:

Rebuilt a real estate site on Wordpress. The site had been established for many years before, and therefor had a ton of Google-crawled property URLs. The new site uses a completely different permalink structure with brand new properties and google search console is coming up with tons of 404 errors.

Old structure: New structure:

I'd like to be able to write a .htaccess redirect to point ALL URLs that start with /0000/00/00/whatever to the home page. I've done some research onregular expressions and I've found similar cases but none that I can make work for me. They seem to just be ignored.

Guide site that I used:

My relevant .htaccess code:

# BEGIN custom rewrite rules
RewriteEngine On
RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/.*/$ [R=301]
# END custom rewrite rules

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Basically my custom redirect is a result of hacking together multiple tutorials on regular expression to try to match the relevant "old" urls. Can someone help me figure this one out? Is my custom redirect in the wrong place? (does it need to be AFTER the wordpress redirect code)? Help would be appreciated!


What is the best way to download and delete a file from the server in a web page?

I am working with a utility that generates archives (.tar|.zip) on the server, and returns a web page with the archive guid file name. I need to put some very simple code/markup on that page that will download the file and and delete it. I'm pretty sure the best approach is to post an HTML DELETE command after the download. I am aware that I have to configure a DELETE handler in the HTTP server and I'm confident I can figure that part out. I'm just looking for the simplest possible way download and delete the file. I'm open to all solutions, perhaps a special "GET ONCE" handler for Apache in combination with a simple target _blank anchor element.

redirect not working with .htaccess

I have this in my htaccess

Options +FollowSymlinks
RewriteEngine On
Deny from all
#RewriteRule (.*)  [R=301,L]
Allow from
Allow from
RewriteRule index.php$ /otherfolder [R=301,L]

I am trying to redirect all the requests to a new folder but for some reason the above does not work.

I have also tried

Redirect 301 / /otherfolder

but that just added other folder again and again to my domain like this


302 redirect in htaccess caches in browser when expires header is added

When I need to send my Wordpress site into maintenance mode, I add this code to .htaccess to redirect to my custom maintenance file:

 <IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.html [R=302,L] 

However, when I remove the code (once my maintenance is complete), it caches in the browser. I know why it does this, because I also have this in my htaccess:

# Performance: EXPIRES HEADER
    <IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 
    # Default directive
    ExpiresDefault "access plus 1 month"
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    # CSS
    ExpiresByType text/css "access plus 1 month"
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"

This code is straight from

It is no problem for me as I can clear my browser cache. But if a user visits my site while it's in maintenance mode, they won't know they have to clear their browser to stop the redirect from caching.

So 2 questions:

  1. How long does this redirect cache for? if it is only a few hours, it doesn't really bother me.

  2. If it caches for a long time, is there some extra code I can add when I add the maintenance code to stop the redirect caching? I could just remove the expires header code when adding my maintenance code which would work, but if I forget to remove it, a user could have the redirect caching for a long time.

Broken images/css in production mode with Rails 4

I'm running a Rails 4 application in production Windows 8.1... For some reason y have broken images and css in production mode. Since there is no Passenger gem in Windows, I have to use Apache config to redirect or reverse proxy to Thin:

<VirtualHost *:8888>
    ServerAdmin [email protected]
    ServerName Depot

    DocumentRoot "c:/my_directory_tree/depot" 

    <Directory "C:/my_directory_tree/depot">
        Require all granted
        Options -MultiViews

    ProxyPass /depot balancer://depot_cluster/
    ProxyPassReverse /depot balancer://depot_cluster/
    ProxyPreserveHost On

    <Proxy balancer://depot_cluster>

    #ErrorLog  "|C:/Webserver/Apache/bin/rotatelogs.exe logs/ 86400" 
    #CustomLog "|C:/Webserver/Apache/bin/rotatelogs.exe logs/ 86400" 



And run my application with:

thin -p 3000 -e production --prefix /depot start -p 3001

I already precompiled my assets, but didn't work either.

rake assets:precompile

Why I'm running in production mode my app? Well... before implementing in a real production server, I need to know how to implement this application in Windows server...