I have a perfectly working website working as the root of my webhost (/public_html), but I recently bought a new domain and parked it there too, so I needed a subdir for it (/public_html/newdomaindir).
Now I need to move my entire website to a subfolder (/public_html/website) and I'm having a hard time adapting the .htaccess files.
This was my old working .htaccess file when it was root:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.org$
RewriteRule ^/?$ "http\:\/\/www\.website\.org\/" [R=301,L]
#SetEnvIfNoCase Host ^www\.website\.org$ require_auth=true
RewriteCond $1 !^(index\.php|images|css|robots\.txt|js|icons|files|fonts|extplorer)
RewriteRule ^(.+)$ /index.php?/$1[L,QSA]
And now the webhost support suggest that I have this .htaccess file as root, to redirect traffic.
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} website.org$
RewriteCond %{REQUEST_URI} !website/
RewriteRule ^(.*)$ website/$1
But, well... it's not working as expected. My website is broken.
Should I use a different approach, maybe ask the support guys to change the document_root of my website? Should I change anything in the subfolder .htaccess file?
Any help is greatly appreciated. Thanks.
Not my strongest skill, but I would try to modify your previous .htaccess to following form:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.org$
RewriteRule ^/?$ "http\:\/\/www\.website\.org\/" [R=301,L]
# not sure what about this
#RewriteCond $1 !^website\/(index\.php|images|css|robots\.txt|js|icons|files|fonts|extplorer)
RewriteRule ^$ website/ [L]
RewriteRule ^(.+)$ website/index.php?/$1[L,QSA]
If this does not work, maybe you will find some clues in this SO answer.
Related
enter code here Hi I've the following code inside my htaccess file.
My wildcard subdomain routes to "mainfolder" - here i placed the htaccess file.
I've the following folders
"mainfolder"
"mainfolder/sub1"
"mainfolder/sub2"
etc.
Calling the subdomain - sub1.domain.com it should route to the subfolder "sub1" (subfolder=subdomain).
I tried to do it with this code
#Redirect to subdomainfolder if no special page is called
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^$ %1/index.html [L]
#Redirec to subdomainfolder if a special page is called
RewriteCond %{HTTP_HOST} ^(.*)\.domain.com(.*)$ [NC]
RewriteRule ^(.*) %1/$1 [L]
The first rule works well, but if I add the second rule I receive a internal server error.
Whats wrong with this - how how I can change the first rule in this way, that it works with all url-parameters after .com - that was the reasons for me to add the second rule.
Hope I get help for this. thanks a lot.
A lot of web hosts today provide an easy implemention for subdomain creation in their administration panels. You just need to to go there, choose you subdomain name, and then point it to a directory in your tree.
If you can't, then it will be a little more complicated (You will need to resolve that subdomain to your server ip, configure some virtual hosts ... etc) and you may not have enough privileges to do that (unless you are on a dedicated server).
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/subfolder/(.*)$ http://subdomain.example.com/$1
LIke
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^sub1/(.*)$ http://sub1.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^sub1\.example\.com$
RewriteCond %{REQUEST_URI} !^sub1/
RewriteRule ^(.*)$ /sub1/$1 [L,QSA]
If more understanding step wise then follow https://beginnersbook.com/2013/08/redirecting-from-subdirectory-to-subdomain-using-htaccess/
I have a multilanguage website in joomla. The FaLang component creates the following URLs:
www.myDutchDomain.nl/nl/
www.myDutchDomain.nl/en/
www.myDutchDomain.nl/de/
I have 2 other URLs which should redirect to English and German URL:
www.myEnglishDomain.eu >> www.myDutchDomain.nl/en/
www.myGermanDomain.de >> www.myDutchDomain.nl/de/
After redirect I want to see myEnglishDomain and myGermandomain in URL. If I'm not mistaken it's called server alias.
How can I create a server alias for this purpose?
You should be able to use mod rewrite to solve this by adding lines to your .htaccess file, allowing anything on your country domains 'www.myEnglishDomain.eu/{wildcard}' to be rewritten to the country path '/en/{wildcard}'.
First you must make sure that the bindings for each domain are pointing to this website.
Then add the following lines to your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.myEnglishDomain.eu$[NC]
RewriteRule ^(.*)$ /en/$1 [L]
RewriteCond %{HTTP_HOST} ^www.myGermanDomain.de$ [NC]
RewriteRule ^(.*)$ /de/$1 [L]
If you need the domain within the browser to update to myDutchDomain.nl, then doing the following instead:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.myEnglishDomain.eu$ [NC]
RewriteRule ^(.*)$ http://www.myDutchDomain.nl/en/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.myGermanDomain.de$ [NC]
RewriteRule ^(.*)$ http://www.myDutchDomain.nl/de/$1 [R=301,L]
For further help, here is a mod rewrite cheat sheet: http://www.cheatography.com/davechild/cheat-sheets/mod-rewrite/
Disclaimer: I have not been able to test the above rules, please let me know if this contains syntax or other errors so to maintain an accurate reference for other people.
I am trying to deploy my site online and the .htaccess file which worked perfectly in the localhost seem not be be working the same way on my share hosting domain.
i have a public folder in the root(htdocs) folder which is meant to serve the public files and I used two .htaccess files one in the public directory and the other in the the root(htdocs) folder.
.htaccess for htdocs folder
RewriteCond %{HTTP_HOST} ^mysite\.morehere\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.morehere\.net$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule (.*) /public/$1
and that of the public directory
# --- Homepage
RewriteRule ^home$ index.php [NC]
RewriteRule ^home/$ index.php [NC,L]
# --- articles page
RewriteRule ^articles $ articles.php [NC]
RewriteRule ^articles /$ articles.php [NC]
........
My intention is to make the URLs search engine friendly and appealing to users.
Edit: I have made sure mod_rewrite on the production server is turns on but the pages still gets redirected to the not found page.
Like mysite.morehere.net/home/ is redirected to the not found page
Can anyone please help me out to figure out where the problem is.
Check if mod_rewrite is turned on, on your production server
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.
I hope all of you are having a great week!
I have moved a code ignite site to a new server, When I moved it across I tested it here.
http://31.25.190.77/~freelanc
Where it works perfectly, so then I pointed the domain name at it.
http://www.freelanceentrysolutions.co.uk/
but not it doesn't work! Only the homepage works but if I click another link I get
Not Found
The requested URL /supply-and-installations.html was not found on this
server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Any ideas here?
Kind Regards, Brad
SOLVED
I added this to the HTACCESS
RewriteEngine On
RewriteCond %{HTTP_HOST} ^freelanceentrysolutions\.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.freelanceentrysolutions\.co.uk$
RewriteCond %{REQUEST_URI} !^/index.php/
RewriteRule (.*) /index.php/$1
It work perfectly with http://www.freelanceentrysolutions.co.uk/index.php/supply-and-installations.html !
i think the 'index.php/supply-and-installations.html' is problematic.
You might need to put index.php in all of your links?
/index.php/supply-and-installations.html
Try
http://www.freelanceentrysolutions.co.uk/index.php/supply-and-installations.html
or rewrite URLs to achieve this without using index.php
MODIFICATIONS:
If you are on apache put following in a .htaccess file and put that in root folder.
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Another good version is located here:
http://snipplr.com/view/5966/codeigniter-htaccess/
SOLVED! I added this to my HTAccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^freelanceentrysolutions\.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.freelanceentrysolutions\.co.uk$
RewriteCond %{REQUEST_URI} !^/index.php/
RewriteRule (.*) /index.php/$1