unfortunately I don't know how to start.
I have the following file structure:
.htaccess
|- site1
|- .htpasswd
|- index.php
|- site2
|- .htpasswd
|- index.php
So I need a dynamically baseurl depending on the sub-subdomain.
When I enter http://site1.preview.domain.com I want the baseurl pointing to site1.preview.domain.com/site1. But in browser it should still be http://site1.preview.domain.com
Furthermore I want to protect each "site"-folder. So is it possible to dynamicly point to the htpasswd?
Thanks in advance for suggestions.
In the root .htaccess you can have this rule:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(site1|site2)\.preview\. [NC]
RewriteRule !^(site1|site2)/ %1%{REQUEST_URI} [L,NC]
Related
I think there are many htaccess redirect samples but I can't find a case similar to mine.
I have many sub folder my root
/suppliers
|- /suppliers/abc
|- /suppliers/xyz
/merchants
|- /merchants/abc
|- /merchants/xzy
etc.
I want to redirect them when I type
/m/yyy -> /merchants/yyy/index.php
/m/yyy/abc -> /m/merchants/yyy/abc.php
/m/yyy/abc/ -> /m/merchants/yyy/abc/index.php
Can anyone advise me on how I can do that?
You may use these rules in site root .htaccess:
RewriteEngine On
# /m/yyy rule
RewriteRule ^m/([\w-]+)/?$ merchants/$1/index.php [L,NC]
# /m/yyy/abc rule
RewriteRule ^m/([\w-]+)/([\w-]+)$ merchants/$1/$2.php [L,NC]
# /m/yyy/abc/ rule
RewriteRule ^m/([\w-]+)/([\w-]+)/$ merchants/$1/$2/index.php [L,NC]
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.
My .htaccess file looks like this:
#Options FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([a-zA-Z0-9\-\/]*[a-zA-Z0-9])$ index.php?_path=$1&%1
Here is my file structure:
example.com/
|- rewriteTest/
| |- images/
| | |- logo.png
| | |- icon.png
| |- style/
| | |- housekeeping.css
| | |- style.css
| |- .htaccess
| |- index.php
The desired behavior is that
example.com/rewriteTest/any/path
should point to
example.com/rewriteTest/index.php?_path=any/path
AND
example.com/rewriteTest/images
(without the leading slash) should point to
example.com/rewriteTest/index.php?_path=images
AND
example.com/rewriteTest/images/logo.png
should point to
example.com/rewriteTest/index.php?_path=images/logo.png
The rewriting works if the path is not an existing directory or file. However, if, say, I navigate to the /images directory, the url in my browser (Chrome) changes to /images/?_path=images and shows a 403 page. And if I navigate to /images/logo.png, the image opens up, instead of showing the page at /index.php?_path=images/logo.png.
Why is this happening and how do I fix this?
Your regex seems to be an issue. Try this:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /rewriteTest/
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{QUERY_STRING} !(^|&)_path=[^&]+ [NC]
RewriteRule ^(.+)$ index.php?_path=$1 [L,QSA]
Also to open a directory URL use a trailing slash like http://domain.com/images/
I'm having trouble with .htaccess config...
List files and folders content:
/
src/
css/
admin/styles.css
user/styles.css
js/
admin/init.js
user/init.js
I want to access the file/folder path will matching paths rewrite
http://domain/src/css/staff/styles.css => src/css/admin/styles.css
http://domain/src/css/styles.css => src/css/user/styles.css
http://domain/src/js/staff/styles.js => src/js/admin/init.js
http://domain/src/js/styles.js => src/js/user/init.js
And here is my code:
RewriteRule ^src/staff/(.*)$ src/admin/$1 [L]
RewriteRule ^src/(.*)$ src/user/$1 [L]
But apparently things not working, there was an error has occurred "500 Internal Server Error".
If you just take a look at my problem and share a bit of your science, I'd be very grateful. Thanks!
With more regex matching you can use these 2 rules:
RewriteEngine On
RewriteBase /
RewriteRule ^(src)/(js|css)/staff/([^/.])+\.(css|js)$ $1/$2/admin/$3.$4 [L,NC]
RewriteRule ^(src)/(js|css)/([^/.])+\.(css|js)$ $1/$2/user/$3.$4 [L,NC]
Current directory structure:
wwwpublic
|+ spanish(language)
|-- index.php
|-- contact.php
|
|- index.php
|- aboutus.php
|- products.php
|- contact.php
In the root of wwwpublic directory I have files in the English language. Since site have Spanish language too, I have created separate directory named 'spanish'. Name of pages are exactly the same in both directories.
Now, some pages in spanish directory don't exist and I need to redirect request to such pages to root folder and retain name of file requested.
Example:
Visitor go to Spanish version, open index.php there, then he clicks on aboutus.php page (dont exists) inside spanish directory and then .htaccess redirects him to the /root/aboutus.php
Try something like this in your wwwpublic directory, preferably before any routing rules you may have:
RewriteEngine On
# conditions to check that current request doesn't point to a valid resource
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# condition to check that request is for the /spanish/ directory
RewriteCond %{REQUEST_URI} ^/spanish/(.+)$
# conditions to check if the /spanish/ is removed whether it would point to a valid resource
RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
# all conditions match, rewrite
RewriteRule ^/?spanish/(.+)$ /$1 [L]