If I have a site mysite.com and in the root of the site I have a /holding/index.html file, how can I write my .htaccess to show the index of the holding page without showing the URL mysite.com/holding/ in the address bar.
Here is my directory structure:
public_html
└── .htaccess
└── holding
└── index.html
└── assets (css, img)
└── email-signature
└── assets (img)
My .htaccess is currently:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/email-signature/assets/logo.jpg$
RewriteCond %{REQUEST_URI} !^/email-signature/assets/spacer.gif$
RewriteCond %{REQUEST_URI} !^/holding/(.)*$ [NC]
RewriteRule ^(.*)$ /holding/ [R=302,L]
But this shows mysite.com/holding/ in the address bar ... I want it to stay as mysite.com but still show the holding page index. Is this possible?
The email signature assets need to be accessible at mysite.com/email-signature/assets/... (I'd also like to not have to specify each file in the .htaccess but just wildcard all jpg,png,gif files in email-signature/* as accessible).
Thanks in advance.
You can refactor your rule to this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/email-signature/ [NC]
RewriteRule !^holding/ /holding/ [NC,L]
Remove R=3xx flag to avoid external redirect
Add this just below section of your page's HTML: <base href="/holding/" /> to resolve relative paths of css/js/images etc.
Related
I am trying to write a htaccess file that will allow for /example/1/profile to look for a JavaScript file within /example/. Currently on Internet Explorer 11 it is looking for /example/1/file.js whereas realistically it should be looking for /example/file.js.
This needs to be done inside of the .htaccess file as the setup that the website currently has.
I know there is a way in which you can redirect 404 to /example however this is resulting in a 200.
Is their a way I can say in the htaccess file that if it is .js .css to look in /example?
Thanks in advance
EDIT:
For a little but more information, my current htaccess is like this
DirectoryIndex index.php index.html
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /example/index.php [NC,L]
It is for php because the php echos a file_get_contents of the index.html which is an Angular project.
So I need this htaccess to be the following logic
If the file is a .js or .css then rewrite the location to /example else rewrite the location to example/index.php.
The reason this is happening is because I am doing a format which has the ID as a second parameter and for some reason this is interfering with the way that the URL is structured for the js, css.
I imagine this line is what is breaking it...
RewriteRule ^(.*) /example/index.php [NC,L]
Converting my comments to answer. This appears to be problem due to relative links.
To fix, you can add this just below <head> section of your page's HTML:
<base href="/example/" />
so that every relative URL is resolved from that base URL and not from the current page's URL.
I have a folder export that is accessible to all my subdomains:
/export/sub1/...
/export/sub2/...
/export/sub3/...
Right now, regardless of what subdomain you're on, you can see all of the content by changing the directory in the url.
It's not a security issue, but more of a canonicalization concern, but I'd like to use an .htaccess file to rewrite the folders so people see a modified path that matches up with their subdomain:
sub1.domain.tld/export/... is served from /export/sub1/...
sub2.domain.tld/export/... is served from /export/sub2/...
sub3.domain.tld/export/... is served from /export/sub3/...
How can I do this?
You can use this generic rule in site root .htaccess:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+) [NC]
RewriteRule ^/?export/(.*)$ /export/%1/$1 [L,NC]
How are you today,
I have a problem in url rewriting..
I Upload my website on pesco sub-directory, Like www.example.com/pesco and my css path like this /css/style.css but when site run css must be like www.example.com/pesco/css/style.css but my css showing like this www.example.com/css/style.css url rewrite missed the pesco sub-directory
Please any one give me the solution
My Code is below you can see.
ErrorDocument 404 /notfound.php
RewriteEngine on
RewriteBase /pesco/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.html index.php
RewriteRule ^aboutus.html aboutus.php
RewriteRule ^([a-zA-Z0-9_-]+).html$ products.php?catid=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).html$ detail.php?category=$1&product=$2
I think your error is just a reference problem. You can try ./css/style.css as this means it looks to find css as a directory inside the same directory as the file requesting it, whereas /css/style.css is essentially looking in the root directory
I have my website in a subfolder from the main root.
www.domain.com ---redirects to---> www.domain.com/Folder1/
using:
RewriteEngine on
RewriteCond %{SERVER_NAME} domain.com [OR]
RewriteCond %{SERVER_NAME} www.domain.com
RewriteRule ^(.*)$ http://www.domain.com/Folder1/ [R=301]
this is working fine...
I also have a administrative WebApp located on Folder2. Folder2 users will always enter the direct URL to Folder2.
http://www.domain.com/Folder2/Version1/
It is at the same structure level as Folder1.
Problem is that when I try to access my webapp, its not working anymore and redirecting it to the Folder1 website.
Question: What htaccess code do I need to add to keep my webapp (folder2) working by not redirecting it to Folder1, while still making all regular users go to Folder1.
Customer facing Website: www.domain.com/Folder1/
Internal Admin Website: www.domain.com/Folder2/Version1/
In Folder2 you should add the following line to .htaccess
RewriteRule .* - [L]
This rewrite rule takes precedence over the .htaccess in the parent directory.
I need to allow direct access on a specific folder name (and subcontents) via .htaccess, and deny all other.
To start, my current .htaccess is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
My file structure is, for instance:
modules/
core/
_test/
publics/
file.txt
other/
_whatever/
publics/
more.txt
publics/
sub/
file.txt
other.txt
.htaccess
I could not access anything, except by files and folders that are in publics folder. On this example, I could access, without problem:
modules/core/publics/ [dir]
modules/core/publics/file.txt
modules/other/_whatever/publics/ [dir]
modules/other/_whatever/publics/more.txt
modules/other/publics/ [dir]
modules/other/publics/sub/ [dir]
modules/other/publics/sub/file.txt
modules/other/publics/other.txt
I could not have access to any file or folder.
I guess that we will need regular expression, but I don't know how I can use this on mod_rewrite to works like I want.
Some suggestion?
A slight modification to your current htaccess. Any access not under a publics folder will be redirected to index.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !publics/
RewriteRule . index.php [L]