.htaccess mod_reqrite not working - apache

So I am trying to use mod rewrite in apache2 to make it going from this link:
http://website.com/site/player.php?name=_Joosh
to using
http://website.com/site/u/_Joosh
Here is what I have tried so far in my .htaccess file I have.
RewriteEngine On
RewriteRule ^u/([A-Za-z0-9-+)/?$ player.php?name=$1 [NC,L]
And I have checked rewrite is an enabled mod in apache and I have added
Options FollowSymLinks ExecCGI
to my vhost file. Any help please?

You can use the following rule in your /mainpvp/.htaccess
RewriteEngine On
RewriteRule ^mainpvp/u/([A-Za-z0-9-+)/?$ /mainpvp/player.php?name=$1 [L]

Related

Apache redirect simple url to the same named php file

I'd like to redirect some static pages to the same named php file.
This is the code I'm using:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^services$ services.php [L,QSA]
</IfModule>
I'm getting 404 error when I open the "/services" url. If I change it to
RewriteRule ^services-anything$ services.php [L,QSA]
I can open "/service-anyting" without any problem.
Does anybody have any idea?
Thanks
Instead of your rewrite rules you can just enable MultiViews option:
Options +MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

How to do a RewriteRule when the folder name is equal to an existing file name?

Given the following Folder "de":
.
..
index.php
faq.php
If I try to fire a RewriteRule from my .htaccess (in the parent directory) like this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^de/test/ de/faq.php [NC,L]
... it works totally fine, but if I try it like this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^de/faq/ de/faq.php [NC,L]
then the Apache returns a "404 Not found" instead of firing the RewriteRule.
Why does this happen?
Options +FollowSymLinks -MultiViews
If MultiViews is enabled, it will try to search for similar files and folders hence why the rule doesn't work, when you disable it, it stops doing that which is why it works.
For a more in-depth investigation, you may enable your RewriteLog within your web server:
RewriteLog "/some/path/to/file/rewrite.log"
RewriteLogLevel 3
This way you can see how it behaviors and what it looks for when MultiViews is enabled and disabled.

Mod_ReWrite doesn't work on cakephp

I have recently deployed CakePHP however mod_Rewrite is not currently working:
I have the following in my apache2.conf
<Directory "/path/to/the/app">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
i have run
sudo a2enmod rewrite
which stated the module is already enabled and i have also checked the .htaccess file which has
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
has anyone got any other ideas as to why mod_rewrite isn't working?
Please note i have restarted apache with no sucess
There must be 3 .htaccess files in these locations
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
Do you have them?
Turns out mod_rewrite was working, however I was using cakephp 1.3 which doesn't detect if the mod_rewrite works but applys a CSS style which wasn't applying to the div. it works now anyways

httpd.conf rewriterule

None of my RewriteRules seem to be working...
I have tried many variations, but none of them seem to be read.
RewriteEngine On
RewriteRule (.*) http://www.domain2.com$1 [R=301,L]
Do you have some log ? If not, enabled RewriteLog and use a hight RewriteLogLevel: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog
Also, don't forget to enable rewrite module.
a2enmod rewrite
And use a conf like this:
<Directory /var/www/website/html>
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*) http://www.domain2.com$1 [R=301,L]
</IfModule>
</Directory>
wrapped in VirtualHost tag and it worked.

mod_rewrite works in .htaccess files but not in apache2.conf

I have the following in a .htaccess file as a test:
RewriteEngine on
RewriteRule ^(.*)$ /backend/$1
This works as expected. I was able to get rewrite logging working with the following in apache2.conf:
<IfModule mod_proxy.c>
RewriteLog "/tmp/REWRITE.log"
RewriteLogLevel 9
</IfModule>
The log file is created and logs debug info as expected. However, when I delete the .htaccess file, change the apache2.conf directive as follows, and restart apache to do the equivalent globally, it doesn't work.
<IfModule mod_proxy.c>
RewriteLog "/tmp/REWRITE.log"
RewriteLogLevel 9
RewriteEngine on
RewriteRule ^(.*)$ /backend/$1
</IfModule>
I'm using Apache/2.0.55 on Ubuntu.
Help!
Have you tried this ?
RewriteEngine on
RewriteRule ^(.*)$ /backend/$1
<IfModule mod_proxy.c>
RewriteLog "/tmp/REWRITE.log"
RewriteLogLevel 9
</IfModule>
Because this way I was able to do rewriting, but log didnt worked hence a issue in mod_proxy.c
Have you considered turning RewriteEngine on before any other rewrite directives?
Are your RewriteRule directives contained within a particular server definition? Do you have virtual servers at work?
The reason I ask this is that you say this works in an .htaccess file which is directory specific; although officially the documentation says that RewriteRule can apply to server config, virtual host, directory, .htaccess.