I can't figure out why my redirects aren't working as they are in another htaccess file.
I'm trying to redirect old urls to new ones.
RewriteEngine on
AddDefaultCharset UTF-8
DirectoryIndex index.php index.html
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
</IfModule>
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule (.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Redirect /private_3 http://website.com/new_private
I've tried all sorts of things that I've found on the web but nothing works.
Please help.
Thanks.
Instead of using this:
Redirect /private_3 http://website.com/new_private
Try adding this right below the RewriteEngine on line:
RewriteRule ^private_3(.*)$ http://website.com/new_private$1 [L,R=301]
Looks bad ordering and mixing of mod_alias with mod_rewrite might be a problem here. Try reordering your rules as this:
AddDefaultCharset UTF-8
DirectoryIndex index.php index.html
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
</IfModule>
RewriteEngine on
RewriteRule ^private_3 http://website.com/new_private [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteRule ^(system.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1
Related
I'm getting an ERR_TOO_MANY_REDIRECTS error on my website. I have set up a .htaccess file on my Apache server containing the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) index.html [L]
RewriteRule ^index\.html$ - [L]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
</IfModule>
This is cobbled together from two sources: Ember.js' routing tutorial and a guide to forcing HTTPS.
There must be some kind of redirect loop somewhere here, but I am unable to determine where it's coming from.
Update: I was able to get it working using the following.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [L]
RewriteRule ^index\.html$ - [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
I have the following lines in my .htaccess
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ seo.php?p=$1 [L]
RewriteRule ^seo/site:(.*)$ seo.php?p=seo&domain=/$1&status=seo [QSA]
RewriteRule ^seo/(.*)$ seo.php?p=seo&domain=/$1&status=seo [L]
RewriteRule ^admin/page:(.*)$ seo.php?p=admin&page=/$1 [L]
RewriteRule ^webagent/page:(.*)$ seo.php?p=webagent&page=/$1 [L]
RewriteRule ^setlang:(.*)$ seo.php?setlang=/$1 [L]
RewriteRule ^(.*)/setlang:(.*)$ seo.php?p=/$1&setlang=/$2 [L]
</IfModule>
The problem is that only first Rule works normal. it takes pages from currently defined folder in php
When i try to open
seo/domain.com
it doesn't work but when i open
seo.php?p=seo&domain=domain.com&status=seo
works very well.
Where i go wrong with this .htaccess file.
Have your rules like this:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^seo/site:(.*)$ seo.php?p=seo&domain=/$1&status=seo [L,QSA]
RewriteRule ^seo/(.*)$ seo.php?p=seo&domain=/$1&status=seo [L,QSA]
RewriteRule ^admin/page:(.*)$ seo.php?p=admin&page=/$1 [L,QSA]
RewriteRule ^webagent/page:(.*)$ seo.php?p=webagent&page=/$1 [L,QSA]
RewriteRule ^setlang:(.*)$ seo.php?setlang=/$1 [L,QSA]
RewriteRule ^(.*)/setlang:(.*)$ seo.php?p=/$1&setlang=/$2 [L,QSA]
RewriteRule ^(.*)$ seo.php?p=$1 [L,QSA]
</IfModule>
I have the below code in my .htaccess file, this all works fine.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteRule ^(.*),(.*)$ $2.php?rewrite_params=$1&page_url=$2
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
RewriteRule ^stores/([0-9a-z.-]+)/?$ shop.php?shop_id=$1 [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/ajax_files/watch_item\.php$ ajax_files/watch_item.php [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/ajax_files/save_field\.php$ ajax_files/save_field.php [L,QSA,NC]
RewriteRule ^stores/([0-9a-z.-]+)/images/form-cb-icons\.png$ images/form-cb-icons.png [L,NC]
RewriteRule ^group-break/([0-9]+)/[0-9a-z.-]+/?$ group_break.php?cb_id=$1 [L,NC]
RewriteRule ^group-breaks/([a-z]+)-[a-z-]+/?$ group_breaks.php?tab=$1 [L,NC]
However I'm trying to add a new rule at the bottom which is this:
RewriteRule ^billing/client/login/?$ login.php [L,NC]
However this doesn't appear to work. Not sure if it matters or not but the billing directory also has a .htaccess file which may be overwriting it? The contents of that file are below:
<Files ~ "\.(pdt)$">
order deny,allow
deny from all
</Files>
# Protect against Clickjacking
#Header append X-Frame-Options "SAMEORIGIN"
RewriteEngine on
# Force HTTPS
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=307,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php
RewriteCond %{REQUEST_URI} ^(.*)/install.php$
RewriteRule install.php %1/install/ [R=301,L]
I wanted to put my code in the root .htaccess file as the one inside the billing dir is for other software which may get overwritten.
Can this be done?
Yes your guess is right. If /billing/.htaccess exists with some rewrite rules then you need to add this rule in /billing/.htaccess file:
<Files ~ "\.(pdt)$">
order deny,allow
deny from all
</Files>
# Protect against Clickjacking
#Header append X-Frame-Options "SAMEORIGIN"
RewriteEngine on
# Force HTTPS
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=307,NE,L]
RewriteCond %{REQUEST_URI} ^(.*)/install.php$
RewriteRule install.php %1/install/ [R=301,L]
RewriteRule ^client/login/?$ /login.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]
How to have requests to be handled by index.php
For instance
If I type SEFs in the browser
http://localhost/friends
http://localhost/me
Rewrites to
http://localhost/index.php/friends
http://localhost/index.php/me
So I could access friends or me from $_REQUEST['PATH_lNFO']
I've mod rewrite on and allow all directive set for the root directory in apache.
Need a .htaccess file,
look in this article http://www.sitepoint.com/apache-mod_rewrite-examples/ for this RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ display.php?country=$1&state=$2&city=$3 [L]
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rtest
RewriteCond %{HTTP_HOST} ^mathpdq\.com
RewriteRule ^(.*)$ http://www.mathpdq.com/rtest/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
http://mathpdq.com/rtest/fred
RewriteRule ^friends$ index.php/friends [L]
RewriteRule ^me$ index.php/me [L]
that's all.
$_REQUEST['PATH_INFO'] will be set to "/friends" or "/me".
(Depending on your server configuration ORIG_PATH_INFO might have to be used instead of PATH_INFO)
Gurus of So
I am trying to redirect any user that comes to http://domain.com to http://www.domain.com. I have found a bunch of different ways to do that on SO, but I need to make them fit the dynamic app config from CakePHP.
Currently, this is what my .htaccess reads:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot [L]
RewriteRule (.*) app/webroot [L]
</IfModule>
I am running Ubuntu 10.04 on a Slicehost slice.
Any help is super appreciated. Thank you.
UPDATE - SOLUTION - Thanks to Rob Wilkerson
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.myapp\.com [NC]
RewriteRule ^(.*)$ http://www.myapp.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]
</IfModule>
From one of my own apps:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.myapp\.com [NC]
RewriteRule ^(.*)$ http://www.myapp.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>