Currently I'm using this .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.org$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.org$
RewriteCond %{REQUEST_URI} !production/
RewriteRule (.*) /production/$1 [L]
so if i'm hit mydomain.org or mydomain.org/* it will pointing to public_html/production folder
But now i need exceptional rules to point mydomain.org/api to folder public_html/api.
How to achieve this?
just for your reference...
try this in your localhost. make one project folder then create one .htaccess file in your root directory
write below code in .htaccess file
RewriteEngine On
RewriteRule ^game/([0-9]+)? http://triviamaker.com [R=301,L]
now run this,
localhost/your_Project_Folder_Name/game/_any_number/ ... when you run this url you will automatically redirect to another url which is set in .access file
I hope you understand this thank you
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 got a subDir with a '.htaccess' file, what I want is when this file recieves a request, the index in the root execute without any change of location in the file ..
Sub dir location : 'public_html/subdomains/news'
I wrote the '.htaccess' file as following
RewriteEngine on
RewriteCond %{HTTP_HOST} ^news\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.news\.example\.com$
RewriteRule ^/?$ ../../index.php?url=news [L,QSA,NC]
but didnt work
As this subDir belongs to a subDomain, I dont want its address changed , I want the user to access the location address:
http://www.example.com/news
Through invoking the address:
http://news.example.com
without them seeing it
You need to make a sub-domain and point that sub-domain to folder.
like news.exmaple.com will be pointed to public_html/news (where news is the folder name)
No need to do any thing in .htaccess file.
For any sub domain request, use this:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.s\.co
RewriteCond %{HTTP_HOST} ^(.*)\.example\.s\.co
RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-z\-]+)
RewriteRule ^(.*)$ /%1/$1 [L]
I am trying to redirect all calls to mysite.com/api/foo/bar/json?param1=1... to mysite.com/api
I've tried
RewriteEngine On
RewriteRule "^api/?(.*)" "/api" [R=302]
But it doesn't work because it redirects in a loop
You need to exclude the destination path you are redirecting to
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/api/?$
RewriteRule ^api/?(.*) /api [R=302]
First check file permission maybe you don't have to made edit on the .htaccess file. Then insert this line of code.
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
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 have created one sub-domain. It is also accessed via folder.
For example,
subdomain.website.com
which is also accessed in the following url
website.com/subdomain
How do i stop this? I think it can be done with htaccess. I am not sure.
In the htaccess file in website.com's document root, add these rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^subdomain.website.com$ [NC]
RewriteRule ^subdomain/?(.*)$ http://subdomain.website.com/$1 [L,R=301]
add following line in the .htaccess in your root directory:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
RewriteRule ^/(.*)$ http://subdomain.domain.com/$1 [L,R=301]