htaccess redirect if index.php is missing - .htaccess

Sorry, I tried everything but cannot get it to run. Any help very appreciated.
I need a very basic staging-system. Everything works fine, but the following .htaccess isn't working...:
`RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_NAME} ^dev.
ReWriteCond %{REQUEST_URI} !DEVELOPMENT/
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/DEVELOPMENT/index.(html|php) !-f
RewriteCond %{REQUEST_FILENAME} !../maintenance/maintenance.html
RewriteRule ^(.)$ ../maintenance/maintenance.html [R=307]
RewriteCond %{SERVER_NAME} ^dev.
ReWriteCond %{REQUEST_URI} !DEVELOPMENT/
ReWriteRule ^(.)$ DEVELOPMENT/$1 [L]
RewriteCond %{SERVER_NAME} ^dev.
[.... same code - different directory: /TESTING]
RewriteCond %{SERVER_NAME} ^www.
[.... same code - different directory: /PRODUCTION]
`
The structure:
root
.htaccess
DEVELOPMENT (directory)
index.php
TESTING (directory)
index.php
PRODUCTION (directory)
index.php
MAINTENANCE (directory)
maintenance.html
Not working:
if "index.php" is missing, a Site is displayed: Title "307 Temporary Redirect" - Content: Temporary Redirect - The document has moved here(link to the same site: iE dev.example.com)
My purpose:
redirect every request to the right folder (dev.example.com -> /DEVELOPMENT)
if file "/DEVELOPMENT/index.php" OR Folder "DEVELOPMENT" is missing -> redirect to "/MAINTENANCE/maintenance.html"
same for "/TESTING" and "/PRODUCTION"
use one .htacess for the whole enviroment (dev.example.com -> /DEVELOPMENT // test.example.com -> /TESTING // www.example.com -> /PRODUCTION)
let Google know, it's only temporary for site updates
Hope, i explained my problem clearly...
Thanks in advance!!!

Related

How to remove this part from URL using htaccess?

I have this URL:
http://www.register.abc.com/myapp/administrator/registration
Which is :
http://www.register.abc.com is my domain
myapp is my aplication folder in server
administrator/registration is my controller and function
What I'd like to do is to remove this part /myapp/administrator/registration from my URL. In default, when user only enter the http://www.register.abc.com/ it will be redirected to my home page. I'd like to set it so the user directly enter registration page not the home page. I have little to no knwledge about .htaccess. Any help is greatly appreciated.
Note: I am using wiredesignz codeigniter modular extensions hmvc
Edit:
my current .htaccess is like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myapp
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
In your site root .htaccess (a level above myapp/ you may try this .htaccess code:
RewriteEngine On
RewriteRule ^$ myapp/administrator/registration [L,R=302]
If you want an internal rewrite (without changing URL) then try:
RewriteRule ^$ myapp/administrator/registration [L]

htaccess redirect root to subfolder - but keep other root subfolders beyond

My server has several system folders and files by default. so for better overview I want to put my website in a subfolder like this:
www.domain.de/web/index.html
ALL links and website-related stuff is found in this subfolder "web". BUT the folder "web" should not be seen in the url!
I got this with these lines in my htaccess and it works:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de [NC]
RewriteCond %{REQUEST_URI} !^/web/.*$
RewriteRule ^(.*)$ /web/$1
But now the problem:
I also want other folder on my server to work. So www.domain.de/downloads/ should work, too. This folder is NOT in the subfolder "web". So if I write the direct url "www.domain.de/downloads" in my webbrowser, I don't want to get a redirect to "www.domain.de/web/downloads/", you know?
Is there any solution? :)
Thanks!
You Can use a RewriteCond to exclude your folder :
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de [NC]
RewriteCond %{REQUEST_URI} !^/download [NC]
RewriteCond %{REQUEST_URI} !^/web/.*$
RewriteRule ^(.*)$ /web/$1

Remove subfolder with htaccess

This is the architecture of my website :
/
app/
index.php
...
libs/
lib1/
file.php
lib2/
...
I need to access index.php by this url : domain.com/index.php
I tried this :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)app
RewriteRule ^(.*)$ app/$1 [L]
It works, but inside my index.php, I call for example :
include('../libs/lib1/file.php');
It's doesn't work because this path refer to root now...
And I can't access to domain.com/libs anymore, because it's looking for domain.com/app/libs.
How can I do ?
The include() shouldn't care what the path the browser sees. That should be based on the local filesystem on the server. But your rules are affecting direct access to the libs, so try adding a few more conditions:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^app/
RewriteRule ^(.+)$ app/$1 [L]
RewriteRule ^$ app/index.php [L]
This makes it so requests for existing files or content won't get routed through the app folder.

HTACCESS: mirror htdocs sub folder to www folder

Since my customers hosting providers domain cpanel doesnt have the possibility to create subdomains, I've been trying to figure out how to mirror a subfolder from my htdocs to my root www folder within my .htaccess.
Root: /domains/{domain.com}/htdocs/www/
Sub: /domains/{domain.com}/htdocs/beta/
I need to keep the subdomain {beta.domain.com} intact to let everything work as planned. So when a customer visits {www.domain.com} or {beta.domain.com} he needs to see exact the same site with the domain kept intact.
DOCUMENT_ROOT is '/etc/apache2/htdocs'
Hope someone can help me out.
This this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^beta\.domain\.com$ [NC]
RewriteRule ^/?$ /www/index.php [L]
At this moment I am helping him.
The hosting provider sucks but i can try to make it a little bit more clear.
The hosting provider build a difficult map structure but if got it, it is the following:
htdocs
domainname ----> SYMBOLIC LINK TO WWW
www
stats
If i want to add an subdomain they build the system as follow,
In the htdocs dir we should make a new map lets call it users.
We make a dir and the directory structure is as follow:
htdocs
domainname ----> SYMBOLIC LINK TO WWW
www
stats
users
Now if we go to: users.domainname.ext we will get directed to the directory users.
Note: This is the only way it's possible to make subdomains at the hosting provider.
Now what i did is add the following .htaccess file in the directory users.
RewriteEngine On
RewriteRule ^(.*)$ www.domainname.ext/ [L]
This will redirect to: www.domainname.ext
Now i added in the .htaccess of the www dir the follow:
# mod-rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^users\.domainname\.ext$ [NC]
RewriteRule ^(.*)$ /$1 [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
The problem is that the subdomain will redirect to the new domain, and what he want's is that url bar shows: users.domainname.ext instead of www.domainname.ext
Note: My .htaccess knowledge aint much but this is as far as i can get. So i bet i have things wrong :p in it but with this i came the farest haha.
Note 2: The part below is used for Zend Framework to work properly!
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

.htaccess file and clean Urls problem

I've been using the same .htaccess file to remove the .php extension in my sites. I can't seem to figure out what doesn't work this time. Its a new hosting provider I registered with.I tried making a simple redirect to SO to see if the file was getting parsed,It does. I read the whole Apache Mod_rewrite book and understand what the file does but there's something I'm missing.Thanks in advance for the help.here's the file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteBase /
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) index.php [L]
Btw It's in the public_html folder which shouldn't make a difference.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^page-name\.html$ page-name.php [T=application/x-httpd-php,L]

Resources