.htaccess RewriteRule don't work - apache

i've been searching on the apache website, stackoverflow's responses, and i couldn't find any answers to me..
All i want is to redirect site.com/stats/ to site.com/pages/stats.php to make the path better and simple. as i said i've been searching it for a whole month, without any answer that could help me... I'm not english so sorry if i made mistakes on this question.
I'm actually on a VPS Debian 7 runing Apache version V2.2.22 (Debian)
My current rules (Maybe wrong ^^) are there :
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.*)$ pages/stats.php <-- not working
RewriteRule ^player/(.*)$ pages/stats_player.p‌​hp?player=$1
I'll really like who will answer this post
FOUND!
i just needed to add these 2 lines :
RewriteRule ^stats/$ pages/stats.php
RewriteRule ^stats$ pages/stats.php

Try this rule
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-]+)$ pages/$1.php
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ pages/stats_player.php?$1=$2 [L]

Related

Apache RewriteRule to hide Folder

I've read a lot of beginner tutorials and other threads here on the topic mod_rewrite, but I can't get my (simple) RewriteRule to work.
My local domain is http://localhost/movies, and my structure is:
/movies
|-.htaccess
|-index.php
|-/pages
|-profile.php
|-faq.php
|-statistics.php
So my URLs would be e.g.:
http://localhost/movies/pages/profile.php
But I want them this way:
http://localhost/movies/profile
I achieved this with simple rules in my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule profile pages/profile.php
RewriteRule faq pages/faq.php
RewriteRule statistics pages/statistics.php
</IfModule>
Now I've tried to sum it up in one rule:
RewriteRule ^(\w+)$ pages/$1.php
So my thought is, that /(\w+)$ captures any characters and puts it in $1
But this doesn't seem to work, so where might be my error?
The output I get: Object not found! 404
Edit:
The answers in the possible duplicate aren't working neither
RewriteRule ^/(.*)$ /pages/$1
Or
RewriteRule (.*) /subfoldername/$1

Removing the second question mark from URL

An external app calls my website with the following URL:
http://www.mydomain.com/index.php?route=checkout/success?ref=56
which is obviously wrong (since it has 2 questionmarks).
How can I write an .htaccess rewrite rule to convert the second questionmark to ambersand (&) ? (http://www.mydomain.com/index.php?route=checkout/success&ref=56)
I have tried this but it does not work.
RewriteEngine on
RewriteRule \? \& [L]
Well after some research, I have come up with this
RewriteCond %{QUERY_STRING} ^(.*)?\?ref=(.*)&?(.*)$
RewriteRule (.*) /$1?%1&ref=%2%3 [L]
I do not know if it's the best but it works for sure
RewriteEngine on
RewriteRule /(.*)?(.*)?ref=(.*)$ /$1?$2&ref=$3 [R]
RewriteLogLevel 9
RewriteLog "/var/log/rewrite.log"
must admit I have not seen it work on my end but it should be nearly there - enabled rewrite log so it can be debugged easier

Having trouble with mod_rewrite

I've been attempting to get a simple rewrite done on a script for over two weeks now.
While it seems like it would be a simple task, any attempts to rewrite..
http://thebluecorsair.com/rank/index.php?character=Timbervvoif
to: http://thebluecorsair.com/rank/Timbervvoif result in the typical 404 response.
I've tried about twenty different answers, pages, as well as rewriting directly with PHP with no luck.
Additionally, what would be the 301 redirect for this as well?
Thank you!
Generated via http://www.generateit.net/mod-rewrite :
RewriteEngine On
RewriteRule ^rank/([^/]*)$ /rank/index.php?character=$1 [L]
To resolve this, I used the following code.
RewriteRule ^([a-z]+)$ index.php?character=$1 [QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)?$ index.php?character=$1 [QSA,L]

Quick mod_rewrite help on GoDaddy

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.

.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?