Replace all requested images with test.jpg in htaccess - .htaccess

I'm trying to replace all requested images with a test image inside my .htaccess file
(running Apache2.2/Coldfusion8) like so:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule \.(?:jpe?g|?:JPE?G|gif|png)$ test.jpg
</IfModule>
The test.jpg is in the same folder as my .htaccess file, which I have cleared everything from except the above snippet.
Problem is, still nothing happens.
Question:
Can someone tell me what I'm doing wrong?
EDIT:
Must be something in the httpd.conf settings I guess. I have set:
AllowOverride All
in the document root directory, but still doesn't do anything.
Thanks for help!

try adding some random text to the htaccess and see if you get a 500 error message. If not, htaccess is not enabled.

Related

.htaccess rule to skip folder name from entire urls

My project name is funfeesa and all client side pages are contains in "client" folder. But I want to access then without to write client folder in the url.
just like below:
localhost/funfeesa/index.php
I have tried many rules in .htaccess file but nothing is working fine.
can anyone help me?
#prevent directory listing
Options -Indexes
IndexIgnore */*
#follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^funfeesa/index.php(.+)?$ funfeesa/client/index.php/$1
Try to access your .htaccess file as above
Still if it doesn't work try by removing index.php from above rules but I think It should work :)

rewrite index.php?p=page to page

My urls currently look like this: http://www.morrisononline.com/index.php?p=contact
I would like to rewrite them to http://www.morrisononline.com/contact
The content for (in this case) contact comes from the directory /pages/ (www.morrisononline.com/pages/contact.php)
I have tried the following in the .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-_]+)/?$ index.php?p=$1 [NC,L]
I have also tried other combinations too (I'm not very good at this and trying lots of suggestions from other forum posts etc) but nothing has any effect. No error messages and no rewrites either. Did I do it wrong or could there be another command before that, that overrides this?
Do I have to refresh some cache or restart the server for this to work?
Make sure you have AllowOverride All or at least AllowOverride FileInfo in your site's config for the site's document root. And make sure the htaccess file is in the document root, is readable by everyone. If it's still not working, make sure that you've got AccessFileName set to .htaccess.

URL Rewriting not working?

im new here.
Im trying to rewrite some urls on my site only for some reason no matter what I try I cannot get them to work!
My directory on my server has the following...
index.php
user-profile.php
.htaccess
On my index.php there is a number of users that all have a view more details button that links through to user-profiles and posts an ID using GET method as such...
http://mysite.com/user-profile.php?userID=2&firstName=Martin&lastName=FAM
However Id like to format them as so...
http://mysite.com/people/2/Martin/FAM
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]
Can anybody give me some reason as too why this isnt working?
The regex should be
^people/([^/]*)/([^/]*)/([^/]*)$
You need to make sure you have this option set in your document root directory in Apache's httpd.conf file:
AllowOverride All

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.

Apache mod_rewrite works in .htaccess but not httpd.conf

I'm experimenting with mod_rewrite for the first time (I'm a web newbie, but trying to learn). I'm trying to get bob.html to redirect to alice.html (read: URL stays the same, page content is alice.html). Both files are in /var/www/. I'm running Ubuntu 10.10 w/Apache 2.2.16.
Here's what works in the .htaccess file placed in the /var/www/ directory:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^bob.html$ alice.html
</IfModule>
This behaves as expected, but it does not work when moved to the httpd.conf file (just learning best practices w/performance and such). I read somewhere that when using mod_rewrite in httpd.conf file, leading slashes are required, so my httpd.conf file looks like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/bob.html$ /alice.html
</IfModule>
I also read that /etc/apache2/sites-enabled/000-default needs to have AllowOverride set to All.
<Directory /var/www>
...
AllowOverride All
...
</Directory>
I think that's just for use with .htaccess but I wasn't sure so I just left it in.
With all of these configuration settings, the redirection does not work. I've tested to make sure the file itself is being read (someone suggested httpd.conf isn't used anymore and apache2.conf is used instead) by inserting erroneous code. I've taken a look at a couple other questions/answers but I still cant figure it out.
Edit: It should be noted that I'm using /etc/init.d/apache2 restart after each change to httpd.conf to restart Apache and (hopefully) reload the configuration.
Try wrapping the rewriterules in your httpd.conf file in <Location /></Location> tags. The seems to alter the behavior making it more similar to the .htaccess file.

Resources