.htaccess not working on my server - .htaccess

I'm working on my project and now I want to transfer it from my localhost to server. Everything seems to work fine, but .htaccess doesn't work.
The server should be suporting mod_rewrite and print_r(apache_get_modules()); shows mod_rewrite running.
But still, when I type myaddress.com/contact, it shows error 404.
Here is the .htaccess file, but it should be fine, since it runs on my localhost:
RewriteEngine on
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&detail=$2 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
Do you have any idea?
Thanks, Mike.

Does the server allow .htaccess? It doesn't really have to.
Try other directives, ask your hosting provider, or check the configuration yourself if possible.

I tried testing your rules they should be fine on urls such as: http://myhost.com/test1 and http://myhost.com/test1/test2 result in requesting url: index.php?page=test1 and index.php?page=test1&detail=test2
So the problem is not your rules, it is your server setup somewhere. As Mewp said check your Apache config file, look for AllowOverride which should be enabled for .htaccess files to overriding default settings.

Ok, fixed it .. deep in the hostings settings, there was an option to activate it .. but I found it after 4 hours of looking around .. :P

Related

How do I remove a folder from a URL?

First of all, this question has been asked a few times on stack, however, none of the answers seem to work for me.
I have a website which has a "pages" folder in the root, I want to store all of my website pages in there.
Here's my structure
/pages/folder/folder2/index.php
I want to make it so the link displays:
https://wwww.website.com/folder/folder2/index.php
Removing the "/pages/" part of the URL, when I try all of the answers suggested previously, I get a 404 error.
Here is the htaccess I'm using
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^pages(/.*|)$ $1 [L,NC]
</IfModule>
and i also tried:
RewriteEngine On
RewriteRule ^pages/(.*)$ /$1 [L,R=301]
This htaccess is in the root. I can't seem to get it working, can anyone offer any suggestions? Thank you!
Your second attempt looks fine, though it can be imporoved a bit:
RewriteEngine On
RewriteRule ^/?pages/(.*)$ /$1 [R=301]
That rule should work inside the http servers host configuration or in some dynamic configuration file (".htaccess" style file) if the http server's rewriting module is loaded. You definitely should prefer the first option, but if you really need to use a dynamic configuration file then take care that the interpretation of such files is configured at all and that the file is placed in your hosts's DOCUMENT_ROOT folder and is readable for the http server process.
If that does not work then you need to start debugging. In this case you will start by monitoring your http server's error log file while making test requests. If no hint appears in there you need to enable rewrite logging which allows you to learn what exactly is going on inside the rewriting engine. See the official dpcumentation for the apache rewriting module for that. As typcial for OpenSource software it is of excellent quality and comes with great examples.

htaccess works with www.example.com but not example.com

I have installed Ghost, which needs nodejs to run. I'm doing this on an Apache Linux server via managed hosting. They kindly let me login with SSH access so I've been able to setup nodejs and Ghost using the standard installation instructions. I installed ghost to the root of my domain so in normal operation someone would go to example.com and it'll show them my blog. Well that's what I'd hoped.
However now when I've come to load Ghost in my browser I discover because I'm accessing it the way I am, and that Ghost doesn't do server configuration, I seem to need an htaccess file to be able to make the site reachable.
So, I have created this htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ http://127.0.0.1:65515/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:65515/$1 [P,L]
</IfModule>
With that saved to the root, if I go to example.com/ghost (the admin panel for Ghost) it works. Nothing wrong there, looks great. If however I try and visit the root, ie goto example.com, instead of showing me the index, it shows me index.js - that is, it literally loads the contents of Ghost's index.js file and displays it instead of parsing it and displaying the main index of the website.
IF however I go to www.example.com then it all works. So whatever the problem is it's because I'm not using www. in the domain.
I would prefer it to work both with or without the www in the URL though. I did try adding some solutions to redirect non-www requests to www.example.com to th ehtaccess but for some reason it still doesn't work (as in if I type example.com it doesn't redirect me to www.example.com).
I think maybe you should be using mod_proxy rather than mod_rewrite. At least, that's what I've used in the past. Apache will catch requests coming in on port 80 and then redirect them to port 65515 where your node server is listening.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
Like this:
ProxyPass / http://localhost:65515/
I figured it out. Wasn't anything to do with htaccess, or Ghost or nodejs or anything like it. No, instead the problem was the sodding server was caching the website. I discovered the setting to delete the cache and it all started working fine, so, this is now solved.

The requested URL /public_html/ was not found on this server

I'm working on a local MAMP website. I use a micro MVC framework to use friendly urls
so I don't need to call index.php (which is inside of public_html directory) in the urls.
To achieve that, I have the following htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) /public_html/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Then I have the following line in /etc/hosts
127.0.0.1 mywebsite
Also, I have the following in httpd.conf
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/mywebsite"
ServerName mywebsite
</VirtualHost>
So if I simply call http://mywebsite from the browser, the whole thing works smoothly.
So what's the problem?
The problem appears if I try to reach the same page from another machine in my LAN.
So if I write http://192.168.1.15/mywebsite the answer is:
Not Found
The requested URL /public_html/ was not found on this server.
I get the same message if I call http://localhost/mywebsite from my own machine.
I have the feeling that is something related to .htaccess, but I've been trying a
lot of different ideas I've found in the web, and nothing works.
I'd like to fix this, because I need other people to check the website from their machines.
If you have any clue please help. Thanks a lot.
Edit: I can't solve this, so as a temporary fix I've created a free account at AppFog for my team to be able to access the page until we go to production.
After all these years, I thought that computing would be easier... it's getting harder, actually. The htaccess file is a huge mistery to me! Thanks anyway :)
By the way... as I told you, I've found a way to fix the problem. The funny thing is I have to use a different .htaccess file. I thought you could be interested, provided that it seems you like computing stuff :)
This is the .htaccess that works in my LAN debian server:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(www/.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
As you can see, it's different from the one I showed you at my first post. My conclusion? Well, even when I always try to keep things simple, life shows me one and another time that everything can be more complicated. Look at the .htaccess file. It's so funny... I've learnt to work with it by using different combinations of code.
Isn't it crazy? Yes it is. Please let's do understandable software. Thank you!
Ok, I've been trying a lot of different things and all of them fail. The only solution I've found is to install the web site in a separated LAN debian server. Everything works ok in that way, but it's not possible to make it work from my machine with MAMP.
Why not? Well, I don't know. After a lot of years in computing, I've learnt to say "I donĀ“t know", you know what I mean.
I've been working for a few days with an AppFog account for free but, you know, that thing cannot work when you put a database and the whole thing there. Obvious.
So at the end the only solution I've found has been to put everything at that local LAN debian server.
Thank you anyway :)

htaccess rewrite working offline on WAMP but not online on linux host

I'm just going to explain my problem here :
http://mysite.com/movie/20000
should be rewritten to
http://mysite.com/movie.php?id=20000
my htaccess file :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie/([0-9]+)$ movie.php?id=$1
On my localhost WAMP installation this works fine, but when I put it online on my linux host it doesn't completely work. It does go to the movie.php page, but it seems it gives no GET parameter id.
Edit :
if I use
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie([0-9]+)$ movie.php?id=$1
then
http://mysite.com/movie20000
Goes to the correct page, but I would like /movie/20000 and not just /movie20000
It also seems that my host automatically rewrites a visit to mysite.com/movie to mysite.com/movie.php
After searching for a long time, and pulling some of my lovely hair out I found the solution.
I just added
Options -MultiViews
to my htaccess file and that fixed it.
Why? Because .php was being added to urls without an extension, which I really did not need.
This should work.
RewriteRule ^movie/([0-9]+)$ http://mysite.com/movie.php?id=$1 [NC,L]
Don't forget the [NC, L] it means Case insensitive, last rule... If you don't, it will continue to process through your htaccess rules, maybe triggering other ones.
Still, the stuff below is good advice.... :)
Check to see if the Rewrite module is loading with apache. Look for this line in the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Check to see if your apache config allows for .htaccess files for your system or in the virtual host definition.
Also, test with a simpler rewrite catch all and test that alone to see if it's working at all like this (get rid of everything else in your htaccess file to limit the test):
RewriteEngine On
RewriteRule ^(.*)$ http://www.google.com [L,R=301]
Any request to your site should go to google if the configuration for apache is correctly set.

url rewriting asp .htaccess file

I just moved my website (asp.net) to the live environment. I realized they are running IIS 6 so all my nice and clean url rewriting doesn't work anymore. I was trying to implement URL rewriting using the .htaccess file.
I want to rewrite:
www.amicobio.co.uk/Menu.aspx to www.amicobio.co.uk/Food-Menu
So in .htaccess I set:
CaseInsensitive On
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^Food-Menu$ Menu.aspx
But it doesn't work it says:
The requested URL
/a/m/amicobio.co.uk/public/Menu.aspx
was not found on this server.
Obviously the path is wrong but what is /a/m/ and how do I fix it? All the files in amicobio.co.uk/public/
Thanks.
I found the solution
it was
RewriteRule ^Food-Menu /Menu.aspx
in stead of
RewriteRule ^Food-Menu$ Menu.aspx

Resources