local .htaccess rewriterule works, but not on rackspace - apache

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.

Related

RewriteCond %{QUERY_STRING}

Here's what I'm trying to accomplish:
http://example.com/real-estate/?group=rentals
needs to go to
http://example.com/real-estate/rentals
Here's what I have in my .htaccess that isn't working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/real-estate/ [NC]
RewriteCond %{QUERY_STRING} ^group=rentals
RewriteRule (.*) http://example.com/real-estate/rentals/? [NC,R=301,L]
</IfModule>
This is very unusual... Typically people want the redirection the other way around....
Your code looks nearly fine, only some minor corrections. But those might be what you are missing:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/real-estate/?$ [NC]
RewriteCond %{QUERY_STRING} ^group=rentals$
RewriteRule ^ http://example.com/real-estate/rentals [R=301,L]
</IfModule>
For this to work the rules have to either be placed directly inside the http hosts configuration, or inside a .htaccess style file in the hosts document root with enabled interpretation of such files.
And a general hint: you should always prefer to place such rules inside the http servers host configuration instead of using .htaccess style files. Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).
Just use this in your .htaccess file:
RewriteEngine On
RewriteRule ^real-estate/([^/]*)$ /real-estate/?group=$1 [L]
It will leave you with the URL: http://example.com/real-estate/rentals. Make sure you clear your cache before you test this.

Incorrectly configured htaccess file that should direct to subdirectory

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

Apache mod_rewrite usually works, but won't work in this folder -- what's wrong?

I have an Apache web server that usually handles mod_rewrite fine. I have a directory called /communications/q/ and I want to rewrite any URI to insert "index.php" before the rest of the entered URI.
For example, /communications/q/something/else should actually serve communications/q/index.php/something/else. It's the standard PHP CodeIgniter setup.
I placed a .htaccess file in the /q/ directory and put the following in it:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
When I even try to go to /communications/q/, I get a 404 Not Found error. Which makes no sense at all because if I comment the .htaccess stuff out, I get the index.php page if I go to /communications/q/, but with the code, I get 404 Not Found.
Anyone spot what I'm doing wrong?
FYI I have a controller called hello, so technically /communications/q/hello should work, but it's a 404, also. But with .htaccess commented out, /communications/q/index.php/hello works fine.
..
==== ADDED NOTE #1 ====
Using CodeIgniter, I should be able to call controllers and functions using the URI structure. So I have a controller called welcome, actually, and then a function called index() which is the default, and a function called hello().
The way CI works, I would write /communications/q/index.php/welcome and I would get the output of the index() function from the welcome controller. And in fact, this works perfectly right now.
Unfortunately, having that weird index.php in the URI is unwieldy and unnecessary, so CI suggests using .htaccess to allow the URI to omit that section of the URI and silently reenter it in the background, using mod_rewrite.
When I add the RewriteRule above, however, it doesn't work. So:
/controller/q/welcome returns a 404 error when it should return exactly the same thing as /controller/q/index.php/welcome. That's the problem. Shouldn't the RewriteRule above make that work?
..
The substitution in a RewriteRule is relative to the DocumentRoot. Based on this, I'd suggest you try:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /communications/q/index.php/$1 [L]
The answer was in the CodeIgniter wiki, in the end. I replaced my .htaccess code with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /communications/q/
# 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]
# When your application folder isn't in the system folder
# This snippet prevents user access to the application folder
# Submitted by: Fabdrol
# Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
And everything worked perfectly. The major relevant change, I think, was adding a ? to the RewriteRule after index.php -- does anyone understand why that's necessary?
Source: http://codeigniter.com/wiki/mod_rewrite/

.htaccess not working

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?

How would I go about creating a mod_rewrite that redirects to launch.php?i=/the/url/that/they/want?

So if the user types mydomain.com/dashboard, the document the server actually sends them is /launch.php?i=/dashboard.
The one caveat is that I would like to leave requests for
/flags
/people
/posters
/css
/icons
/images
/libraries
/patterns
alone, and they should request the actual folder.
How would I create such a mod_rewrite?
This is the .htaccess file for the CakePHP Framework.
Please replace the index.php and ?url= to fit your needs.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
The "!-d" tells Apache to follow existing folders and "!-f" to follow existing files.
Everything else is channelled through index.php
As suggested in a comment, you have to be aware that if it's not working it could be because mod_rewrite is not enabled and you'll not get an error stating that fact, you'll probably only have a HTTP 404.