httpd.conf rewriterule - apache

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.

Related

Rewrite from subdomain to file in .htaccess

this htaccess code work genially on old server, but on new is work perfectly without last RewriteRule. After put adress in web explorer for example sub.domain.com it load index.php. It may be by wrong setting of Apache? Or other?
Thanks a lot
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^hra/([0-9]+)/?$ /game2.php?id=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com [NC]
RewriteRule ^$ /nacitanie.php [L]
in file 000-default.conf on new server in sites-enabled is part of enabling htaccess:
<Directory /home/juraj/WWW>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
in apache.conf on new server is part about htaccess too:
<Directory /home/juraj/WWW>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
The error was in condition of last RewriteRule, where in regular condition on new server must be added option with index.php
RewriteCond %{HTTP_HOST} "^sub\.domain\.com"
RewriteRule "^(index\.php|\?)$" "/nacitanie.php" [L,QSA]

.htaccess mod_reqrite not working

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]

default cakePhp .htaccess file does not work with redirection

I just installed an Ubuntu web server with apache2. I upload a CakePHP project. I also activated rewrite_mod.
# sudo a2enmod rewrite
When navigating to www.mysite.ch/pierre/contacts it states:
Not found
The requested URL /contacts was not found on this server.
In my local webserver, it works and I can see the contact page
If I remove my project and add a file phpinfo.php with the function phpinfo(), it show information about the server configuration and I do not have a message "not found"
I suspect that my redirection does not work.
What do you think?
Which are the basic step to make an Apache2 server working with an .htaccess file?
Here are is my .htaccess file (it is the default cakephp file, I have not changed it)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Here is my httpd_conf file
<Directory /var/www/vhosts/metauxch/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Do you have some idea?
Change AllowOverride None to AllowOverride All in httpd_conf file
Enable mode rewrite,
sudo a2enmod rewrite
restart apache,
sudo /etc/init.d/apache2 restart
I am sorry, I forgetten to write but I did it
sudo a2enmod rewrite
sudo servive apache2 restart
This is done.
I also change this AllowOverride All
The probleme, now is when I enter
http://eflumpc38.epfl.ch/pierre/contacts
It state that te controller pierre (CakePHP) is missing. While pierre is the root and contacts is the controller.
Second point, when I clink on the Contact (root/contacts/)
I have a such URL
http://eflumpc38.epfl.ch/vhosts/pierre/httpdoc/contacts
instead of
http://eflumpc38.epfl.ch/pierre/contacts
Does some thing is wrong here
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
allow from All
</Directory>
When I upload the same CakePHP projet on my usual provider, I do not have this issue.
Thank
try this solution.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
CakePHP app directory (will be copied to the top directory of your application by bake):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
CakePHP webroot directory (will be copied to your application’s web root by bake):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>

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

How to redirect all traffic to Apache document root

I have tinycms application and how could I forward all traffic to document root?
Example:
http://<IP-address>/ADFADSF/adsfadsf --> /
http://domain.com/adsf --> /
Currently, I have this in my .htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymLinks
RewriteRule admin/$ index.php?view=admin [QSA]
Options -Indexes
Thanks.
James
Using mod_rewrite:
RewriteRule ^/?.+$ / [L,R]
Using mod_alias:
RedirectMatch ^/.+ /
This will,m of course, render the RewriteRule admin/$ index.php?view=admin [QSA] rule useless, or at the very least, cause some conflicts. So you should either comment that rule out, or create a special exception where all traffic except admin/ gets redirected.
EDIT:
How Im gonna do that to make an rule except admin/ ?
Here's one way to do it, I'm only guessing that this is the behavior you want. This stuff does not change, it's fine the way it is:
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymLinks -Indexes
Add a:
RewriteEngine On
Then:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(index\.php|admin)
RewriteRule ^/?.+$ / [L,R]
RewriteRule admin/$ index.php?view=admin [QSA,L]
So putting all that together, you have the deny for accessing .htaccess files. Then you have your Options, then your rewrite rules. You need to turn the RewriteEngine on, then redirect any request that isn't /index.php or /admin, then internally rewrite /admin to /index.php.