RewriteEngine on
RewriteCond $1 !^(index\.php|files|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
The website is hosted on the latest version of XAMPP locally. When I load the website with the .htaccess file in place, it won't load at all. I get a server error
What am I doing wrong?
EDIT: Checked log file, here's an error that might help point the issue out. Does this mean that mod_rewrite has not been included?
.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or
defined by a module not included in the server configuration
Change your first line to
RewriteEngine On
Also, replace your RewriteRule with
RewriteRule ^(.*)$ index.php/$1 [L]
If this doesn't help, check your log file. Server errors will normally issue something to the log file.
If that doesn't help, you'd best crank up your RewriteLog and post some of that here.
The first line, as has been pointed out, should be changed :
RewriteEngine On
but you really ought to redirect requests only if they do not already exists (otherwise all your static requests, eg images and css, would go through index.php as well)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Have you made sure to enable mod_rewrite in XAMPP? A quick googling revealed that (at least in older versions of XAMPP), mod_rewrite was not enabled by default. Maybe this is your issue?
Related
I have the following .htaccess file which resides in /home/mydir/foo/sites/bar:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /home/mydir/foo/sites/bar/apache/$1 [QSA,L]
and of course, I have the following directory w/ an index.php file:
ls -l /home/mydir/foo/sites/home/mydir/foo/sites/bar/apache/
index.php
Basically, my problem is I need to redirect all traffic to "/home/mydir/foo/sites/bar/apache/", but I keep seeing
/home/mydir/foo/sites/bar/home/mydir/foo/sites/bar....
... in my error logs.
Any help would be appreciated.
I found the answer. The issue is with the endpoint. I changed it to the following:
apache/index.php
All is good now.
My htaccess on the local works just fine, but when I push to my remote rackspace it doesnt work. I have tried looking up info about rackspaces special config on this area, but nothing is really coming up.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/folder/([^\.]+)
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_URI} ^/folder/([^\.]+)
RewriteRule ^([^\.]+)/([^\.]+)$ $1.php/$2 [NC,L]
</IfModule>
Any suggestions on what I can do or why rackspace wont accept it?
Thanks a lot
Is the rewrite module loaded? If not, it needs to be turned on
Is the allow override for the directory that your htaccess file is in set to All or at least FileInfo? If not, then your server config needs to be setup so that your htaccess file is allowed to override server config settings.
Have you checked your error logs? If something "doesn't work", and is generating an error, your apache server error logs will tell you why.
This problem has been bugging me for a while now.
I have a created a small site engine and I'm using mod_rewrite to tell the engine what page to proccess, SEO friendly links is a bonus :).
This is how it's works today:
the adress http://www.example.com/site/page
becomes http://www.example.com/engine.php?address=page
But what i want is:
the adress http://www.example.com/page
becomes http://www.example.com/engine.php?address=page
Everything works fine if i create a psuedo directory for the calls (/site) but when i try to do the same from the root strange things start to happends.
RewriteBase /
RewriteRule ^site/(.*) engine.php?%{QUERY_STRING}&address=$1
Works fine: /site/about/contacts becomes eninge.php?address=about/contacts
RewriteBase /
RewriteRule ^(.*)$ eninge.php?%{QUERY_STRING}&address=$1
Doesn't work, for some reason /about/contacts becomes eninge.php?address=eninge.php
(.*) means catch anything. Have you tried exluding files and directory before your catch-all ? Because it will cause an infinite recursion without it.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ eninge.php?%{QUERY_STRING}&address=$1 [L]
More information is available in the official documentation: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Update: You should also specify [L] at the end of your rule, to tell Apache to end the rewriting process here.
Check the RewriteLog (this has been updated in 2.4, check current docs if not using 2.2):
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
RewriteLogLevel 3
This will show you exactly what mod_rewrite is doing and allow you to tune your configuration based on its output. Beware - it grows very quickly, and should never be used in production environments.
As an aside, you have some typos in your post - worth verifying that these differ from your config.
RewriteCond %{REQUEST_FILENAME} !^engine.php
RewriteRule (.*) engine.php?address=$1 [QSA,L]
Try this. What you have is causing the rewrite to loop around and first do engine.php?address=about/contacts as you were expecting, but then go around again and rewrite that to engine.php?address=engine.php. Make sense? The [QSA,L] is a Query String Append and Last flag that will add the query string to your URL and tell the rewrite engine to stop looking for rewrites. The RewriteCond %{REQUEST_FILENAME} !^engine.php is to check that you haven't already specified the engine rewrite by ensuring the current URL doesn't start with engine.php. This is necessary if you are writing this in an .htaccess file rather than the .httpd config files.
This htaccess works fine locally, but on GoDaddy the URL isn't caught by the rewrite engine.
RewriteEngine on
RewriteRule ^products/amsoil/(.*)/$ /products.php?amsoil=$1 [L]
RewriteCond %{HTTP_HOST} ^somedomain.com
RewriteRule (.*) http://www.somedomain.com/$1 [R=301,L]
This worked until a few days ago. Basicallywww.somedomain.com/products/amsoil/this-product/ should forward to www.somedomain.com/products.php?amsoil=this-product ....did work, and still works locally however now I just get a 404 error on www.somedomain.com/products/amsoil/this-product/
Any ideas?
I verified that the following script works on our current hosting plans:
RewriteEngine on
rewritecond %{http_host} ^coolexample.com [nc]
rewriterule ^(.*)$ http://www.coolexample.com/$1 [r=301,nc]
There is a possibility that you are on an older version of our hosting plans. If that is the case, you may want to consider upgrading. Check out http://x.co/Zecq for a how-to on upgrading. There is also a link to the 4GH FAQ. Please review that before upgrading to avoid unwanted surprises.
I have a development site on my machine at
localhost/~Jason/hfh/admin/?admin=collections
My .htaccess file is in the /hfh/admin/ directory. It says:
RewriteEngine On
RewriteBase /~Jason/hfh/
RewriteRule ^([A-Za-z0-9\-\_]*)$ index.php?admin=$1
But when I go to
localhost/~Jason/hfh/admin/collections
I get a "page not found" error. Can anyone tell me why?
(This is related to another question at this link.)
If you have the .htaccess file in /hfh/admin/ make that the base to begin with.
RewriteBase /~Jason/hfh/admin/
then you may see what you expect. Also you'll may want a clause to not redirect when the File/Directory exists.
Does typing the expected result URL work?
/~Jason/hfh/admin/index.php?admin=Collections
Edit:
So what happens if you change the whole lot to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~Jason/hfh/admin/index.php?admin=$1 [L]
It looks like that would be sending you to the page /~Jason/hfh/index.php?admin=collections, when you want /~Jason/hfh/admin/index.php?admin=collections.
Try changing the rule to:
RewriteRule ^([A-Za-z0-9\-\_]*)$ admin/index.php?admin=$1
The short, direct answer for now appears to be: you can't use mod_rewrite on your localhost.