How to get images after 503 redirection? - .htaccess

I need some help !
Indeed I've done a redirection for maintenance on my server but images don't show up.
To explain the problem here is how the file are organized :
- assets
- css
- fonts
- img
- slider
- different images
- js
- maintenance.html
- maintenance.enable
- .htaccess
So here's my .htacces :
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
I don't undestand why maintenance.html can't access to his dependences which are located in assets ...
Thanks in advance for your help !

In order to close this:
Here was the solution.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{REQUEST_URI} !/assets #Solution
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html

Related

Is there a way to create fake directories and assign them a value via .htaccess?

The goal is to create a "fake" language subdirectory after the HTTP_HOST following up with the REQUEST_URI.
[Issue]
localhost/public_html causes 404, but localhost/public_html/index works.
Current code:
ErrorDocument 404 /public_html/404.php
ErrorDocument 500 /public_html/500.php
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^$ /en/ [L,R=301]
# ASSIGN ENGLISH LANGUAGE PARAMETER IF NOT FOUND IN URL
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^(en|id|fr|ru|de|es|ro|tr|zh|ar)/ /en%{REQUEST_URI} [L,NC,R=302]
# ASSIGN LANGUAGE PARAMETER A VALUE IF FOUND IN URL
RewriteRule ^(en|id|fr|ru|de|es|ro|tr|zh|ar)/(.*) $2?language=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.]+?)/?$ $1.html [L,NC]
Folder directory:
xampp root folder
[
- public_html
]
website folder (public_html)
[
- .htaccess
- index.php
- contact.php
- style.css
- etc.php
]
UPDATE:
Thanks to anubhava the problem has been successfully solved!
Make sure these 2 rules are your topmost rules:
ErrorDocument 404 /public_html/404.php
ErrorDocument 500 /public_html/500.php
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php)?$ /en/ [L,R=301]
# ASSIGN ENGLISH LANGUAGE PARAMETER IF NOT FOUND IN URL
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^(en|id|fr|ru|de|es|ro|tr|zh|ar)/ /en%{REQUEST_URI} [L,NC,R=302]
# ASSIGN LANGUAGE PARAMETER A VALUE IF FOUND IN URL
RewriteRule ^(en|id|fr|ru|de|es|ro|tr|zh|ar)/(.*) $2?language=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.]+?)/?$ $1.html [L]
Make sure to fully clean browse cache before testing this change.

ht-access how to redirect to a forum topic url?

I would like to know how to use ht-access to redirect my pages which look as follows .com/?page=forums&topic=topic-name to be changed to .com/forums/topic-name?
The rule below redirects all the page names for example .com/forums or .com/polls which i currently use to get my pages to .com/index.php?page=forums.
RewriteRule ^(.+)$ index.php?page=$1 [L]
i would like www.treyarder.com/home to redirect to www.treyarder.com/index.php?page=home as well as www.treyarder.com/forums/topic-name to redirect to www.treyarder.com/index.php?page=forums&topic=topic-name
my topic is at www.treyarder.com/index.php?page=forums&topic=topic-name
my ht-access file as shown below
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L]
RewriteCond %{HTTP_HOST} \.com [NC]
RewriteCond %{REQUEST_URI} !\.\w{2,4}$
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^/]*)/?$ [NC]
RewriteRule ^(.*)$ index.php?page=%1&topic=%2 [L]
ErrorDocument 404 /index.php?pages=404
ErrorDocument 500 /index.php?pages=500
there seems to be something wrong with the below line
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^/]*)/?$ [NC]
does anyone know what it may be? as if i can fix that line then this should hopefully solve my question.
You must remove both ErrorDocument lines from your .htaccess as you're handling all non-file, non-dir requests through your front controller pattern.
You may try these rules in your site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?page=$1&topic=$2 [L,QSA]
## COMMENT OUT THESE 2 LINES
# ErrorDocument 404 /index.php?pages=404
# ErrorDocument 500 /index.php?pages=500
css/js/images issue: It is due to your use of relative links for these resources. Try ANY of these 2 work-arounds:
Use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /
Add this just below <head> tag of your page's HTML: <base href="/" /> so that every relative URL is resolved from that base URL and not from the current page's URL.
okay this was the final outcome which we managed to mix and match until it worked.
RewriteEngine on
RewriteCond %{HTTP_HOST} \.com [NC]
RewriteCond %{REQUEST_URI} !\.\w{2,4}$
RewriteCond %{REQUEST_URI} ^/([^/]*)/([^/]*)/?$ [NC]
RewriteRule ^(.*)$ index.php?page=%1&topic=%2 [L]
RewriteCond %{REQUEST_URI} !\.\w{2,4}$
RewriteCond %{REQUEST_URI} ^/([^/]*)/?$ [NC]
RewriteRule ^(.*)$ index.php?page=%1 [L]

HTACCESS RewriteRule includes /var/www/html/ to URL

I have the next question to you about .htaccess files. This is my folder hierarchy:
ROOT
- docs
- index.html
- terms.html
- privacy.html
- .htaccess
This is following .htaccess file content:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
When I do following request:
https://example.com/docs/terms
The link in my browser looks like:
https://example.com/var/www/html/docs/terms.html
And I want to achieve this:
https://example.com/docs/terms.html
When I do https://example.com/docs/ I receive content from index.php file. How to fix my issue?
How you see the redirect without the R flag?
Try to change
RewriteRule ^(.*)$ $1.html [NC,L]
by
RewriteRule ^(.*)$ /$1.html [L,R=301]
/ is the important thing

How can I bypass the .htaccess in a parent directory?

My question is the same as: Zend Framework 2 without Vhost configuration but the solution didn't solve my problem.
I'm getting a customised 404 page.
my project is in a sub-directory, and I believe the .htaccess in the parent directory is stopping it from working.
note: I can't delete that one because there is another project running there
htdocs/.htaccess:
Options -Indexes
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^transcripts/$ https://spreadsheets.google.com/a/ci4tcm.com/ccc? key=0AodnCB9Mr1K1dFFmbGhOc3V4RjBvNzZxSE9EZ1dtSnc&hl=en#gid=0 [R,NC]
# ErrorDocument 404 /pages/404.html
# ErrorDocument 500 /pages/404.html
# ErrorDocument 403 /pages/404.html
# RewriteRule ^css(/)?$ / [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)$ /download/$1/$2/ [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)/$ /download.php?test=$2&fol=$1
RewriteRule ^download/([A-Za-z0-9.]*)$ /download/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)/([A-Za-z0-9\+.-\s]*)$ /download.php?folder=$1&file=$2 [L]
RewriteRule ^download/([A-Za-z0-9.]*)$ /posters/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)$ /images/wellbeing_posters/pdfs/$1 [L]
AddHandler server-parsed html
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.another-domain\.com\/$1" [R=301,L]
# A bunch of redirect 303's here
# 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]
</IfModule>
# END WordPress
htdocs/booking/ < Zend application here > (solution to other question).
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} = ""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
so my question is, how do I bypass the parent directory .htaccess rule when the user wants to enter the physical sub directory with the Zend Application?
Your edited question added a whole load of stuff to the .htaccess in the parent folder which changes things somewhat. Assuming you're able to edit that htaccess, the easiest thing to do would be to move the ZF rules into it. Just change any lines that include public and add c-booking before it. So as an example, the last line would look like:
RewriteRule ^c-booking/public/.*$ /c-booking/public/index.php [NC,L]
Also be aware that this is a less secure way to host an app. If you have any non-PHP config files, cache files etc. (things that would normally be outside the web root), make sure they aren't viewable through a browser.

Internal redirects issue in .htaccess Wordpress/WPMU

I have a problem with a WPMU site running on my server. Instead of a 404 message for a file I received a 500 server error. I was able to troubeshoot this down to something in .htaccess. I'm receiving this apache error.
[Fri Nov 18 10:00:54 2011] [error] [client xx.xx.xx.xx] Request
exceeded the limit of 10 internal redirects due to probable
configuration error. Use 'LimitInternalRecursion' to increase the
limit if necessary. Use 'LogLevel debug' to get a backtrace.
I commented out the following and then received the 404 error instead of a 500 server error.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Any thoughts on how to troubleshoot this or can anyone tell me why it's redirecting? I'm not a .htaccess pro so anyone that can throw me a bone here would be appreciated.
It seems that the rules generated by WP 3.8 network is faulty so changing it to the code below should work and stop the errors
RewriteEngine On
RewriteBase /
#RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
I can confirm what fne stated to this issue. Thanks for that. But for my configuration:
wordpress subdomain multisite with domain mapping
The following rules worked fine:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

Resources