Accessing the index file in public_html from SubDir - php

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]

Related

.htaccess : Loads a directory by default

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

url redirection working incorrect using .htacess in php

I have one sub domain api.example.com.
my code is on /var/www/html/ folder.
my all sub domain is redirect to /var/www/html folder.
I am use api.example.com to redirect on /var/www/html/api folder. Using .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^api\. [NC]
RewriteRule !^api/ api%{REQUEST_URI} [L,NC]
But the problem is, it is also change my url , api.example.com/api i don't want to change my URL.
when i type api.example.com in browser tab and press enter then it is change into the api.example.com/api and it is open index file of api folder but i don't want to change my URL and it will open index file of api folder.
Change it to this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^api\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?api(/.*)?$ [NC]
RewriteRule ^/?(.*)/?$ /api/$1 [L,NC]
Notice
Delete you Browser Cache before you test. If this still so not what you want, than you have somwere some other rule in place.

mod_rewrite subdomain and clen url in codeigniter

I suppose my domain is "www.domain.com"
and I have a file system
public_html
|----ds
|--application
|--cache
|--controller
...
|--css
|--image
|--system
|--index.php
|----zs
|----fd
public_html is root directory.
I coding in .htacess with have condition this ::
1) ds Directory is subdomain. when URL is ds.domain.com. It mapping filepath in www.domain.com/ds/index.php/
2) I want to clean URL form www.domain.com/ds/index.php/translate/paintext (example full url) to ds.domain.com/translate/paintext (clean url)
how to coding in .htacess ?
/********************************************************************/
I put the .htacess in /ds folder and try to coding :
#subdomain to subdirectory
RewriteCond %{HTTP_HOST} ^www.domain.com/ds/
RewriteRule ^(.*)$ http://ds.domain.com/$1 [L,R=301]
#clean URL from codeigniter
RewriteCond $1 !^(index\.php|lib|css|image)
RewriteRule ^(.*)$ index.php/$1 [L]
What is wrong??
At least one thing that is wrong is your HTTP_HOST. That variable is the hostname, and hostnames contain no URL path info in them. So www.domain.com/ds/ will never exist as a hostname. Change it to:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^ds/(.*)$ http://ds.domain.com/$1 [L,R=301]
The second issue looks fine. But if you want to redirect a request for /index.php to a new URL that doesn't have the "index.php" part, you need a new rule to do that:
RewriteCond %{THE_REQUEST} \ /+index\.php/
RewriteRule ^index.php/(.*)$ /$1 [L,R=301]

Pointing the website http root to a sub folder with htaccess?

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?

How to load contents from different directory for www.website.com

How to display contents from www directory for http://www.website.com
i..e when a user visits http://www.website.com i want to display the contents from /www directory but keep the url same.
I have tried few methods, but for all of them the url changes as well....
Though i want to load the content from http://www.website.com/www/ i want to keep the url as http://www.website.com/
And same for other pages., i..e http://www.website.com/products.php : /www/products.php
You can use an htaccess file
RewriteEngine on
# Only apply to website.com URLs outside the www folder, but ignore real files and folders
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteCond %{REQUEST_URI} !^/www/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /www/$1
# Finally redirect the topmost folder itself
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteRule ^(/)?$ www/index.php [L]
If you are running apache, you can change the root folder in the httpd.conf file (UserDir)
http://httpd.apache.org/docs/2.0/mod/mod_userdir.html#userdir
So you would have to do something like:
UserDir /www/

Categories