I am trying to host a website that is setup with links in the format /css/file.css and /js/file.js and I'd like to set it up in a sub-directory on an existing domain for demo purposes.
So
/demo/css/file.css is the true path
But the demo/index.php references
/css/file.css
I can have a custom .htaccess file within the sub-directory.
Is this possible without touching the main site on my domain?
If the request is for /css/file.css then rules have to be placed in root .htaccess not in /demo/ directory.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^((?:css|js)/.+)$ /demo/$1 [L,NC,R=302]
Related
I have a order page in the following path
https://example.com/backend/web/order
And I want to display it as
https://example.com/order
What should be the htaccess code (please let me know of every step if possible so I can learn also). Where should I place the htaccess file? Inside the backend folder or the root folder.
To change https://example.com/backend/web/order to https://example.com/order you can use the following rule in htaccess in your root folder :
RewriteEngine On
RewriteRule ^order /back-end/web/order [L]
The rule above makes it possible to access your old URL as http://example.com/order .
I have a site https://sitename.com/web (example). So, full path to page is sitename.com/web/index.php. On ftp server there is folder /web which also contain second page file - index-2.php. How to avoid creating /web-2/ folder and redirect index-2.php to sitename.com/web-2 ?
Easy, create an .htaccess file inside the root folder of your site, then add the following lines to it:
RewriteEngine On
RewriteRule ^web-2$ index-2.php [QSA,L,NC]
This site might help you with htaccess:
https://www.htaccessredirect.net/
A nice tutorial on .htaccess files also below:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
I need to access my site that sits in a subfolder from my domain.
The challenge - Due to my hosting structure, all sites are on the master domain's server in subfolders. Domains are mapped to those folders for each site. The master domain, however, is mapped to the server root like this -
• /www/ (root of www.masterdomain.com)
/folder 1/ (root of www.site1.com)
/folder 2/ (root of www.site2.com)
/folder 3/ (root of www.site3.com)
/folder 4/ (desired root of master domain)
If i install my CMS in folder 4 everything is fine, BUT the CMS code creates new assets in the server root (using DOCUMENT_ROOT i think), NOT in the subfolder.
Attempted fix 1:
Use a rewrite to remove subfolder and set all paths to include subfolder.
Failed - CMS acts as desired, but assets still created in the root.
Attempted fix 2:
Map a subdomain to the folder and rewrite URL to remove subdomain.
Failed: CMS works on subdomain and creates assets in the subfolder (win!), but can't rewrite a subdomain.
Attempted fix 3:
Map a subdomain to the folder, and use a proxy flag from the main domain to load content from it invisibly.
Progress made! Main homepage displays with the correct URL, however linked files and subfolders do not work.
So i can now reach my web app from:
app.exampledomain.com (app works perfectly on all fronts)
OR
exampledomain.com (proxy in effect, all subfolders and links broken)
Here's my htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Proxy subfolders
RewriteRule ^exampledomain.com/(.+?)?$ http://app.exampledomain.com/$1 [P,L,NC]
# Proxy main
RewriteRule ^(exampledomain.com)?$ http://app.exampledomain.com/ [P,L,NC]
So why are my subfolders / assets not working? Problem with the .htaccess? Bad logic?
Important notes -
Subfolder pages are called index.php so can be accessed from -
/folder/
The broken links on the page are in this format -
js/foundation.min.js
Thanks.
RewriteRule knows nothing about domain names, it works only with a local path.
Instead, check the domain name in the RewriteCond:
RewriteCond %{HTTP_HOST} ^(www\.)*exampledomain\.com$ [NC]
RewriteRule (.*) http://httpd.apache.org/$1 [P,L]
But using mod_alias or VirtualHost would be a more correct decision here.
I have this project called 'site01'.
It is published as: 'www.example.com/site01'. The pages are like this 'www.example.com/site01/page/1'.
I'm able to route the url to 'www.example.com/site01/1', but can I change the url to 'www.example.com/s/1' through the routes configuration?
Initially I think that you have to use .htaccess way, because the issue is related to the outside of the CakePHP folder.
You can create a new file named .htaccess in the upper folder and write the instruction witch redirect /site01/ to /s/.
sample code for rewrite url:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^site01.*$ /s/ [R=301,L]
Is it possible to set a default folder to access instead of a file like "index.html".
What I'd like to to is make it so that when a person visits my site they get redirected to a folder within the root of the domain. I am using a blogging engine and I need it to show up as the homepage but I don't want to install it in the root because I have other folders and files that need to be in the root directory. And I don't want to put them inside the blogging software's folder. I also don't want to use a 301 or 3XX redirect for SEO purposes.
If there's a way to do what I'm asking let me know. If not, let me know the best option otherwise.
Try this mod_rewrite rule:
RewriteEngine on
RewriteRule ^$ foo/bar [L]
This will rewrite requests to the directory where this rule is applied to to foo/bar. So if you put this rule in the .htaccess file in your document root and request http://example.com/, it will get rewritten to http://example.com/foo/bar.