I have built my site to live and all my assets are coming back as 404.
The an example link to the assets is 'http://www.mydomain.co.uk/assets/css/normalize.css';
I know all my assets live in /web. so when I add /web to the URL and it works,
'http://www.mydomain.co.uk/{web}/assets/css/normalize.css';
I have added a directory index to my root .htaccess which has helped my site load app.php but this does not seem to work for my assets what am I missing?
//
.htaccess
DirectoryIndex /web/app.php
//
Regards,
To change the document root via .htaccess
add the following to your .htaccess in your server root
RewriteEngine on
RewriteCond %{HTTP_HOST} ^my-domain.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.my-domain.co.uk.co.uk$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
Explained:
RewriteEngine on
//Enable Rewrites
RewriteCond %{HTTP_HOST} ^my-domain.co.uk$ [NC,OR]
//Regex expression that matches people who find your domain without the www.
RewriteCond %{HTTP_HOST} ^www.my-domain.co.uk.co.uk$
//Regex expression that matches another way to your domain
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
// from the root file look for the file which you would like to set as your root mine was www/web - and app.php was in there
Related
I have to upload a directory by default when someone comes to my static website
this is the structure
under my public_html I have domain folder 'domainname'. In domain folder I've webfolder/fr/index.html
I want to load files under webfolder/fr directly. following is my .htaccess under the domain name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domainname$
RewriteCond %{REQUEST_URI} !webfolder/fr/
RewriteRule (.*) /en/$1 [L]
if I remove fr/index.html it loads files under webfolder. If I set
RewriteCond %{REQUEST_URI} !webfolder/fr/
it gives 500 internal error.
Please help me how can I fix this.
To Clarify:
When I open my domain www.domain.com I want it to open www.domain.com/webfolder/fr
Please add following two lines to allow a specific file to load just in case there is no default index file setup already
Options -Indexes
DirectoryIndex index.html index.php
Note : if you have to load first php index file then you have set like
DirectoryIndex index.php index.html
So you want to redirect your domain from root folder to some other subfolder
try this code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname$ [NC,OR]
RewriteCond %{HTTP_HOST} ^domainname$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /webfolder/fr [L]
hope this code will work for you
optional:-you can also do this by changing your home directory in cpanel settings
I have my directory like this:
/index.php (website main page)
/sites
site1
site2
site3
when I go to site1.example.com, i want it to show example.com/sites/site1/index.php
when I go to site1.example.com/page1, i want it to show the file example.com/sites/site1/page1.php
how can i do that? thanks!
I assume all your subdomains point to the same place as the main domain, so subdomain.example.com and example.com point to the same place.
Try something like the following in the .htaccess file in the root of the main site:
RewriteEngine On
# Exclude requests for the www subdomain
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ - [L]
# Requests for the site root
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule ^$ sites/%1/index.php [L]
# Requests that are "assumed" to be .php files
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule ^([^.]*)$ sites/%1/$1.php [L]
# All other requests
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule !^sites/ sites/%1%{REQUEST_URI} [L]
This assumes that a valid URL-path does not contain a dot.
%1 is a backreference to the captured group in the CondPattern (ie. the subdomain) and $1 is a backreference to the captured group in the RewriteRule pattern.
However, how do you want to handle non-PHP files and other static resources?
Also, how can I do a 404 page?
You can define a custom error document. For example:
ErrorDocument 404 /errors/404.php
However, you'll need to make an exception at the top of your .htaccess file to prevent this from being rewritten by the directives that follow. For example:
RewriteRule ^errors/ - [L]
You need to:
Setup a Wildcard DNS record
Write a rule for your .htaccess
The rule could look like that:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/sites/%1/$1 [L,NC,QSA]
That's it.
This question has probably been asked for over a thousand times, but I've tried so many scripts, and googled so long while finding nothing, I thought, let's just ask.
I simply want m.daltonempire.nl to be redirected to daltonempire.nl/m/ without the user seeing the URL change.
So if m.daltonempire.nl/hello.php is requested, I want the user to keep seeing this URL, while the page given is actually daltonempire.nl/m/hello.php.
Note: I do not want www., so simply http://m.daltonempire.nl
Thanks in advance,
Isaiah v. Hunen
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^m\.daltonempire\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ m/$1 [L]
The %{REQUEST_FILENAME} conditions would let you access /exists.php and not rewrite it to /m/exists.php. Remove those two if you want to rewrite even if that may potentially override existing files and directories.
Try this example:
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule (.+)$ "http://example.com/%1" [L,P]
Any requests http://test.example.com will be mapped to http://example.com/test/...
Try googling dynamic subdomain with php and htaccess to get better search results.
I have set CNAME of my sub domain below:
blog.mydomain.com
to my wordpress that installed in folder /blog/ under root directory.
Formerly I need to use this url to call wordpress:
http://blog.mydomain.com/blog/
which is ugly. I have tried many code to redirect:
http://blog.mydomain.com/
to the folder so I can use it as my wordpress url.
Finally I got .htaccess setting that is work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1
I have also CNAME other subdomain: http://forum.mydomain.com to mybb installation in folder /forum/mybb/ so the .htaccess need to put [L] on each of RewriteRule code as below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^forum\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/forum/mybb/
RewriteRule (.*) /forum/mybb/$1 [L]
RewriteCond %{HTTP_HOST} ^blog\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1 [L]
In case you want to use the code please don't forget to set the site url and cookie path in the application config file follow to the setting to make the redirection work properly.
How can I use RewriteRule to point the website http root to a sub folder?
I always use the rule below but now after upgrading to the latest wamp server, it does not working anymore. Why?
RewriteRule ^/?$ local/applications/bin/oldsite/index.htm [L,QSA]
I want to point, for instance,
http://mysite.com/ to http://mysite.com/local/applications/bin/oldsite/index.htm
or in localhost wamp server, it should be like this,
http://localhost/mysite/ to http://localhost/mysite/local/applications/bin/oldsite/index.htm
Any ideas?
And also,
http://localhost/mysite/contact.htm to
http://localhost/mysite/local/applications/bin/oldsite/contact.htm
http://localhost/mysite/about.htm to
http://localhost/mysite/local/applications/bin/oldsite/about.htm
EDIT
I managed to point the other pages to the specific locations with the rule below,
RewriteRule ^([a-zA-Z0-9\-]+)\.htm/?$ local/applications/bin/oldsite/$1.htm [L,QSA]
But still I cannot point
http://localhost/mysite/ to http://localhost/mysite/local/applications/bin/oldsite/index.htm
UPDATED
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#### localhost sets of rules
# No target file, go to index.php
RewriteCond %{HTTP_HOST} localhost [NC]
RewriteCond %{REQUEST_URI} ^/mysite/?$
RewriteCond %{REQUEST_URI} !index\.htm [NC]
RewriteRule . mysite/local/applications/bin/oldsite/index.htm [R=301,L]
# Target file, go to file
RewriteCond %{HTTP_HOST} localhost [NC]
RewriteCond %{REQUEST_URI} ^/mysite/([^\.]+)\.htm [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . mysite/local/applications/bin/oldsite/%1.htm [R=301,L]
#### Live site set of rules
RewriteCond %{HTTP_HOST} (?:www\.)?mysite\.com [NC]
RewriteCond %{REQUEST_URI} !index\.htm [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule . local/applications/bin/oldsite/index.htm [R=301,L]
The first sets of rules are for the local host and redirect permanently:
http://localhost/mysite/filename.htm
To:
http://localhost/mysite/local/applications/bin/oldsite/filename.htm
When filename.htm is not present in the incoming URL, filename.htm in the substitution URL is always index.htm
The string mysite is assumed to be a fixed string while filename is assumed to be a variable.
The second rule-set is for the web server and redirects permanently only
http://mysite.com/
To:
http://mysite.com/local/applications/bin/oldsite/index.htm
In the last case, if the incoming URL holds any additional path the rule is not applied.
For silent mapping, remove R=301 from [R=301,L].
Copy the above sets of rules into both .htaccess files in the local and remote root directories.
This might get you started (untested):
Check in a condition whether the request does not point to a particular subfolder. If so, redirect the request to a subfolder. You can use in the target if you want. Instead of the HTTP Status 301 you can use another one if more appropriate.
RewriteCond %{REQUEST_URI} !^/(local/applications/bin/oldsite/.*)$
RewriteRule ^(.*)$ http....n/subfolder/%1 [R=301,L]
It seems like you want to make the "oldsite" directory your Document Root - right?
I have a sales script based on codeigniter and it's working great
I built an api for it, and am using it via: http://www.mysite/api/getdata
so I want now to access this api via a sub domain, like: http://www.api.mysite/getdata
as I think the solutions is: to redirect all *.mysite.com to mysite.com and then modify the .htaccess, but I don't know is it true?
----------------------------------------Update----------------------------------------
My current .htaccess File
<IfModule mod_rewrite.c>
# Check if mod_rewrite module loaded and we can work with SEO urls
SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
# RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ ./index.php [L]
</IfModule>
If you are using some kind of hosting service that lets you create a subdomain and point it to a document root, you can try creating a www.api.mysite domain and make the document root where mysite's /api directory is. That would get around the need to use an htaccess file. Alternatively, if you have access to your virtual host config, you can do the same thing, creating a vhost for www.api.mysite and point the document root to the /api directory.
If you don't have any control over that stuff, you'll need to setup the *.mysite.com to point to the same site as www.mysite and use an htaccess file. Something like this in the htaccess file in the document root should do the trick:
RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.)?api.mysite [NC]
RewriteCond %{REQUEST_URI} !^/api/
RewriteRule ^(.*)$ /api/$1 [L]