I have a small web app that I'm in the process of deploying to a server. However, suddenly the htaccess file isn't working (not the index file, but when I go to a url such as /login). It keeps maintaining that the file doesn't exist, however, the file that it displays as "unfindable" definitely does exist. I checked the relative path /home/sites/xxx.co.uk/public_html/index.php displayed by the error with a file_get_contents and it shows the file.
DirectoryIndex index.php
Options -Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/])/?$ index.php?route=$1 [L,QSA]
Does anyone know what is happening?
Sorted it, it was just something with my Hosting Provider. The site was being tested on a test url they provided (while the domain is registered) and they had a strange method of identifying your folder (needed /home/sites to be removed)
Related
What I'm trying to do is to enable a 'dry' version of url rewriting in Apache only to check if it is working and actually do not rewrite anything yet.
The simplest .htaccess that I came up with is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
But this still doesn't work. All files, all paths I'm trying to request, no matter if they exist or not return 403 Forbidden
What I need is any example htaccess that has redirection inside that must work, that is allow access to all existing files and folders and do it's job only when the file requested doesn't exit.
The problem was that I've not added these lines:
Options +SymLinksIfOwnerMatch
or
Options +FollowSymlinks
I have pages in my site where the url segment are automatically filled depending on the values of the fields in the page.
And example url is:
http://example.com/students/uk/nikki/86/18-25
where nikki/86/18-25 are dynamic segments.
What I was to do is to simple make an htaccess redirect rule where if a user will go to:
http://example.com/students/uk/nikki/86/18-25
they will automatically be redirected to:
http://example.com/student/uk/nikki/86/18-25
So it's just to make the students segment to student. And since the nikki/86/18-25 segments changes per page, they would be retained during the redirect.
Is this possible in htaccess?
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs):
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^students/uk/([^/]+) student/uk/$1 [L,R,DPI]
Once you are satisfied that the redirect works, you can change the R to R=301 to make it permanent.
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All
I've got a CMS installed in a sub-directory of my webspace and I'm having a little trouble figuring out how to configure the htaccess file.
mysite.com contains a splash page that should stay there for now. The idea is that mysite.com/dev should open the index page of the CMS. I suppose I could go with a subdomain but I'll have to research what to do in this case. Either way all of this is just temporary so whatever works is good.
You can see from the below code I've been messing around and I've commented out a lot of stuff. (I've also not bothered to copy more that I think is probably nonsense.)
#Display PHP Errors
php_flag display_errors Off
RewriteEngine On
RewriteBase /
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.mysite\.com\dev [NC]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php?q=$1 [L,QSA]
I should note that I'm with a hosting company any my root path is something like
/content/hosting/l/u/mysite.com/web
I've tried to add this (and truncated versions) to my htaccess file but without success.
If dev is your CMS and you want site/dev to open index.php in dev, your htaccess file for dev only needs this line:
DirectoryIndex index.php
I have http://example.com/pic1.jpg, pic2.jpg, pic3.jpg, and so on for hundreds of jpgs, on my original server, but I need to move it to http://example.com/pictures/pic[##].jpg. Many different servers and pages link to these pictures, so if at all possible, I don't want to just move the pictures and change the links. Is it possible to include another directory as a second document root in Apache?
So, even though the picture is actually located at /pictures/pic1.jpg, linking to just /pic1.jpg will work fine too?
Edit: I don't want to symlink because of the clutter from having so many pictures in the root.
You can use a .htaccess file in root directory to redirect all requests to pictures directory when there is no file in root with that name.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /pictures/$1 [L]
An about main question. No it is not possible to have two document root (Not acceptable from logical point of view too). But you can redirect requests using .htaccess file.
In my httpd.conf file, for the document root, I have the following block now:
<Directory />
Options FollowSymLinks
AllowOverride None
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) http://example.com/pictures%{REQUEST_URI}
</Directory>
So, if you try to go to http://example.com/pic1.jpg and it doesn't exist, it will then redirect you to http://example.com/pictures/pic1.jpg. This could be made better, like only doing it when REQUEST_URL contains .jpg, but it works for me for now.
I use the following .htaccess code to make my URLs cleaner:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
It basically check if the requested URL points to a file or a directory and if it doesn't, it formats it in a particular way.
The problem is that my production server seems to ignore file extensions when it checks if the requested URL points to a file. For example, it would consider the URL /contact pointing to a file named contact.jpg if a file with that name existed on the root of the server.
What causes Apache to behave like that and what can I do to control it - make it strict about file extensions?
I believe it's because of MultiViews option.
Try Options -MultiViews in the .htaccess