I wanted to put the index.php file of my website in a public file on my server, but consequently, when I tap the url, it is not directing me to the index, but to the folder which contains all of the folder of my website.
I try to put a .htaccess file in the root of the folder containing my website. It worked with my local virtual host wampserver, but not with the real host (where I put files with filezila). I show you the line code I wrote in .htaccess, which worked with wampserver, but not with the actual used server for internet ::
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ public/index.php [QSA,L]
I try also to put the absolute path but same thing. Does someone have an idea about what I have to do to config the index path of my server ? (for a subdomain) ?
I found the solution. I had to remove the first line:
Options +FollowSymlinks
My server already had it activated and didn't support the instruction twice.
Related
I have a folder in my web root called docs and I need to ensure that files in this directory cannot be accessed by non authenticated users.
I have a file in this directory called index.php that verifies whether the user is logged in and serves up the requested file accordingly.
So in order to catch requests for files, in docs I have created the following .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^(.*)$ index.php?requested_file=$1 [QSA,L]
</IfModule>
This works if I navigate to /docs/index.php then index.php is called. However if I navigate to /docs/cat.jpg then I am sent directly to cat.jpg. But I shouldn't be able to access this file...
Can anyone advise what I am doing wrong here please?
Well I tried your exact code on my Apache based stack and it works fine
So There is nothing wrong with your apache instructions
May be you are using php or IDE's inbuilt live servers. For that to work you need apache based stack like Lampp, Wampp, Xampp or Mampp.
I have a FuelPHP application that I'm trying to setup to extend an existing website (we'll call it example.com). The FuelPHP installation is in a directory called listings within the DocumentRoot. However, the main index.php file for the application is located in a subdirectory of listings called public, so the actual path to the index.php file is <DocumentRoot>/listings/public/index.php. The static assets (JavaScript, CSS and images) for the application are in subdirectories of the public directory as well.
I want people to be able to access the application at /properties. Also, there will be requests made for other pages (such as /properties/admin) as well as requests for static assets (such as /properties/assets/css/style.css).
I've got this thing about 90% working. The .htaccess file in the DocumentRoot looks like this:
RewriteEngine On
RewriteRule ^properties/?(.*)$ /listings/public/index.php/$1 [L]
Inside the public directory, there is another .htaccess file that looks like this:
Options +FollowSymLinks -Indexes
RewriteEngine on
# Send request via index.php (not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I set the $base_url in the FuelPHP config to http://example.com/properties/. All of the URLs for the static assets are appearing the way I would expect them to, for example, the path to my bootstrap.css file appears as http://example.com/properties/assets/css/bootstrap.css. This is what I expect. However, instead of Apache grabbing the static asset, it's running the request though the FuelPHP index.php file, resulting in a 404.
I think I need to add a RewriteCond to the .htaccess file that is in the DocumentRoot, but I'm not exactly sure if that's correct, or what that RewriteCond would look like.
How do I adjust my .htaccess file(s) so that I'm able to access static assets such as http://indyapm.com/properties/assets/css/bootstrap.css which is actually located at <DocumentRoot>/listings/public/assets/css/bootstrap.css?
I believe what you want is a RewriteBase
RewriteEngine On # after this
RewriteBase /properties/ # insert this
That, having your main config set up with the correct base url should do the trick.
I am working on a website that has a URL such as the following:
http://www.domain.com/directory/home.php
I was wondering if it is possible to set up the site so users can access it like so:
http://www.domain.com/directory/
And the browser will automatically find and render the home.php file?
Many thanks in advance!
Assuming you are using Apache, from the docs:
The DirectoryIndex directive sets the list of resources to look for,
when the client requests an index of the directory by specifying a /
at the end of the directory name. Local-url is the (%-encoded) URL of
a document on the server relative to the requested directory; it is
usually the name of a file in the directory. Several URLs may be
given, in which case the server will return the first one that it
finds. If none of the resources exist and the Indexes option is set,
the server will generate its own listing of the directory.
Add this to the httpd.conf file :
DirectoryIndex home.php
Then to remove the .php from the URLs, add this to the .htaccess file in the root folder.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
I've never had a problem with cakePHP before, but something's odd about this server and is causing the redirects in the .htaccess files to behave oddly.
CakePHP uses mod_rewrite in .htaccess files to redirect requests to its own webroot folder. The problem is that the redirects are listing the wrong path and causing a 404 error. My CakePHP application, which is stored in the listings directory, has a .htaccess file as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [R=301,L]
RewriteRule (.*) app/webroot/$1 [R=301,L]
</IfModule>
(*note that the R=301 causes an external redirect so we can see what is going on from our end. It should really omit this flag and do the redirect internally, transparent to end-users)
This is supposed to redirect any request from http://hostname.com/~username/listings/ to http://hostname.com/~username/listings/app/webroot/
However, rather than simply adding “app/webroot/” to the end as it is supposed to, it is adding the full server path ( /home/username/public_html/listings/app/webroot/ ) resulting in the final URL http://hostname.com/home/username/public_html/listings/app/webroot/ which is obviously incorrect and triggers a 404 error.
The hosting is on a shared hosting account, so that limits what I can do with the settings. I've never seen this happen before, and I'm thinking it's something wrong from the hosting side of things, but if anyone has some helpful suggestions then I can put them to the hosting company as well.
The solution to your question can be found towards the bottom of this page in the cakephp book:
For many hosting services (GoDaddy, 1and1), your web server is actually being served from a user directory that already uses mod_rewrite. If you are installing CakePHP into a user directory (http://example.com/~username/cakephp/), or any other URL structure that already utilizes mod_rewrite, you'll need to add RewriteBase statements to the .htaccess files CakePHP uses (/.htaccess, /app/.htaccess, /app/webroot/.htaccess).
I've deployed CakePHP from my profile's public_html folder as well. I had to change 3 the same .htaccess files mentioned above. Just add RewriteBase /~username/ to the .htaccess files just after RewriteEngine on!
Try removing .htaccess from main file... It worked for me
It was quite simple (using uolhost shared host):
Edit both .htaccess files:
/webroot/.htaccess
/.htaccess
Add the following line:
RewriteBase /
Here is the whole /webroot/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
i'm hosting a website through a hosting company [1] on a linux/apache server. until now i serve the different content through one script with parameters. an example url is
www.mydomain.com/pages.php?date=1-10-2008
now i want to change the scheme the url is composed of to something which looks completely like a path url. eg.:
www.mydomain.com/pages/date/2008/20/1
for this i need to switch off the normal mapping of url paths to directory folders in apache: all requests to all paths should go to one central script (pages.php), which than analyzes the path component of the url.
how do i tweak apache for this? i hope some .htaccess rules could the trick.
[1] btw, the hosting company is godaddy.com.
Something like:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . pages.php
should rewrite every request for a file or directory that doesn't exist to pages.php. This will allow you to keep static files (images, stylesheets, etc) in the same document root.
(Shamelessly stolen from WordPress :) )
You are looking for mod_rewrite. Example htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^pages/([^/]*)/(.*)$ pages.php?$1=$2
Rather than parse the url in your script, you should be able to handle the specific example above with Apache's ModRewrite module.
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
You can use these in the .htaccess file, assuming your host allows this.