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]
Related
I have an apache server for the system https://theveganhut.co.uk ; I need to have different sites in the same server. So, I put the files for http://theveganhut.co.uk in a folder theveganhut.co.uk in the public_html folder.
I have mapped the domain theveganhut.co.uk to the folder theveganhut.co.uk via the .htaccess file in the root(public_html)
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?theveganhut.co.uk$
RewriteCond %{REQUEST_URI} !^/theveganhut.co.uk/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /theveganhut.co.uk/$1
# Change example.com to be your main domain again.
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?theveganhut.co.uk$
RewriteRule ^(/)?$ /theveganhut.co.uk/ [L]
But when I load the url http://theveganhut.co.uk/admin , the admin login page is seen, but the URL changes to http://theveganhut.co.uk/theveganhut.co.uk/admin/. I want the url to be http://theveganhut.co.uk/admin/
Is there something I am missing in the .htaccess file to address this issue? Please help.
I am currently hosting a website using the Silex framework on a shared server and I have a problem...
Silex is like Symfony, there is an app.php file located in a /web/ subfolder : the website is then only accessible via the URL website.com/web/. I cannot create a virtual host as it is a shared server, so I think the solution is to use an .htaccess file...
I managed to redirect website.com to website.com/web/ automatically but I don't really like this option. I would rather website.com pointed directly to website.com/web/ but I don't know how to do this by just using a .htaccess file. I have been trying to solve this problem for hours now and it's killing me...
At the moment I use this file :
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ web/app.php [QSA,L]
</IfModule>
but it just redirects you from website.com to website.com/web
Is there anyway I can make the root url directly point to the /web folder with a .htaccess file?
Thank you very much :)
If you want access to http://example.com/subdirectory just by typing http://example.com this should work.
# .htaccess main domain to subdirectory redirect
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/ [L]
Try this htaccess configuration:
DirectoryIndex web/app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/web/
RewriteRule (.*) /web/$1
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /web/app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
My working Conrete5 site recently developed a "no input file specified" problem on ALL admin pages. The root of the problem appears to be that admin pages have an unnecessary /index.php in the URL. I.E.
www.example.com/index.php/login/do_login......
If the /index.php part is removed from the URL the page will load (though all referenced files will still have /index.php hence fail to load).
I have concrete running in a sub directory but the page urls are from root e.g.
www.example.com/concrete-page-title...
This is the .htaccess file in my root directory relaying concrete requests to the concrete sub-directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.example.co.uk/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^example.co.uk$
RewriteRule ^/?(.*)$ http://www.example.co.uk/$1 [R=301,L]
# redirect concrete
RewriteCond %{REQUEST_URI} !^/concrete
# permit normal access to wordpress installation
RewriteCond %{REQUEST_URI} !^/news
RewriteRule ^(.*)$ concrete/$1 [L]
</IfModule>
I have pretty urls turned on, here is the .htaccess file in my concrete sub-directory (/concrete).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
Sidenote:
cgi.fix_pathinfo=1 (have changed to 0, no change)
And the site is not hosted with GoDaddy.
The sites been for a fair while now with no updates, despite my fiddling I have had no success so any suggestions greatly welcome.
Something that worked on a site where the server's PHP had been upgraded:
in config/site.php add:
define('SERVER_PATH_VARIABLE', 'REQUEST_URI');
define('DIR_REL', '');
I am using Ubuntu 12.10. And I am having trouble removing the "index.php" from my codeigniter site URL.
My .htaccess files looks like this, I have my code inside hmvcExample folder.
*
RewriteEngine On
RewriteBase /hmvcExample/
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
*
And my I have removed "index.php" from config.php as well. But I still get the following error when i try to load the site without "index.php"
Not Found
The requested URL /hmvcExample/signup was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Please Help. Thanks.
This seems to be one of the question should have been looking for - How to remove "index.php" in codeigniter's path
And there is another config that you need to edit:
$config['uri_protocol'] = 'AUTO';
Change the line written above to the following:
$config['uri_protocol'] = 'REQUEST_URI';
If you have done all of this, there still might be one issue left - enable mod_rewrite
MAKE sure you have AllowOverride All set up in the /etc/httpd/conf/httpd.conf (centos apache 2.2)
config:
$config['index_page'] = '';
I have been working on my own mvc framework to further my web app learning, but am having trouble serving static resources. I am trying to have a single entry point into the application, aka a front controller, so in my project / I have an .htaccess file that redirects all requests to the app/ folder where another .htaccess passes the request uri to index.php (in app/) who delegates the request to the appropriate controllers.
However, when I try to serve up static content, such as javascripts or cascading style sheets, I still get redirected through app/index.php. I am also getting "favicon.ico does not exist in /var/www" errors in /var/log/apache2/errors.log (maybe because of symlink to ~/www?). I do not expect to because of the following .htaccess file in the root directory of my project root:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
# ----------------------------------------------------------------------
# Suppress the "www." at the beginning of URLs
# ----------------------------------------------------------------------
# The same content should never be available under two different URLs - especially not with and
# without "www." at the beginning, since this can cause SEO problems (duplicate content).
# That's why you should choose one of the alternatives and redirect the other one.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
#----------------------------------------------------------------------
# Route static resources to respective files
#----------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond public/$0 -f
RewriteRule ^.+\.(jpg|gif|png|ico|css|js)$ /public/$0 [L]
#----------------------------------------------------------------------
# Redirect all other requests to the app folder
#----------------------------------------------------------------------
RewriteRule ^$ app/ [L]
RewriteRule (.*) app/$1 [L]
</IfModule>
and here is the .htaccess in my app/ folder:
<IfModule mod_rewrite.c>
RewriteEngine On
# ensure request is not path to filename or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# redirect all requests to index.php?url=PATHNAME
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Why can't I serve static content correctly? This would make sense to me if I wasn't trying to sent all static requests to public/, which is where my css, jpg, png, js, etc files reside. But I have a RewriteCond rule in there to send the requests for such files to the public dir... Confusing?
Assuming, from what I understood, that your project structure is the following:
/
/.htaccess
/app/.htaccess
/app/index.php
/public/static.js (for example)
Here is what I come up with, hoping it'll solve your problem:
the .htaccess in the root folder:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^public/.+\.(jpg|gif|png|ico|css|js)$ - [L]
RewriteRule ^(.*)$ app/$1 [L]
</IfModule>
And the .htaccess in the app folder is unchanged.
Every request starting with public and being a file with the listed extensions won't be redirected which is done with the dash character.
The last rule allows to redirect a request to the app/index.php file.
I think the resulting behaviour is the expected one:
static files in the public directory are not redirected,
files with another extension in the public directory will be
redirected to app/index.php (maybe for some error treatment),
requests not starting with public will be redirected to
app/index.php.