I have a lot of urls in the following format.
index.php?option=com_letflat&task=view&id=42
index.php?option=com_letflat&task=view&task=ajaxmap
I want to rewrite all urls that contain option=com_letflat to the root of the domain, ie http://www.example.com
I have tried dozens of different things, and none seem to work.
I have got as far as this:
RewriteCond %{QUERY_STRING} (^|&)option=com_letflat [NC]
RewriteRule ^index.php(.*) http://www.example.com [R=301,L]
But it doesn't work.
Thanks
You can use this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)option=com_letflat(&|$) [NC]
RewriteRule ^index\.php /? [R=301,L]
Just make sure this is very first rule in your .htaccess
Related
I am trying to redirect all URLs on my site (let's call it www.site1.com) except one in my .htaccess file. I currently have the following in my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/my/page$ [NC]
RewriteRule (.*) https://www.site2.com [R=302,L]
With the above, all requests to www.site1.com are redirected to www.site2.com, including the one that I do not want to redirect.
After some experimentation, I have found that the following works to redirect only a specific page:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/my/page$ [NC]
RewriteRule (.*) https://www.site2.com [R=302,L]
I'm not sure why the ! operator isn't working as I expect. Perhaps there is an error in my regex?
Some additional bit of information. This is a Drupal site running on a dedicated cPanel host. But I have been sure to put this new redirect rewrite rule before all the other Drupal-specific rewrite rules.
Any help would be greatly appreciated.
RewriteCond %{REQUEST_URI} !/(index.php) [NC]
RewriteRule ^(.*)$ index.php [NC,QSA,L,END]
You need to make sure you exclude the page you redirect to from you list of possible url that get redirected(to avoid the loop) and then you can add more before the RewriteRule.
RewriteCond %{REQUEST_URI} !/(index.php) [NC]
RewriteCond %{REQUEST_URI} !/(index_new.php) [NC]
RewriteRule ^(.*)$ index.php [NC,QSA,L,END]
I have the following example urls that i need redirecting to www.example.co.uk
http://www.example.co.uk/wordpress/?feed=comments-rss2
http://www.example.co.uk/wordpress/?feed=rss2
http://www.example.co.uk/wordpress/?cat=518
http://www.example.co.uk/wordpress/?cat=514
http://www.example.co.uk/wordpress/?cat=520
http://www.example.co.uk/wordpress/?cat=521
http://www.example.co.uk/wordpress/?cat=523
http://www.example.co.uk/wordpress/?cat=515
http://www.example.co.uk/wordpress/?p=119
There are many more urls further to this list that all have a wordpress/ notation.
Would I have to write a conditional rewrite for each like this:
RewriteCond %{QUERY_STRING} ^feed=comments-rss2$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
RewriteCond %{QUERY_STRING} ^cat=518$
RewriteRule ^/wordpress/?(.*)$ http://www.example.co.uk [R=301,L]
or is there a rule i can write that redirect all urls that have /wordpress in them to redirect to www.example.co.uk
I believe a single rule like would be suffice:
RewriteCond %{QUERY_STRING} (^|&)(feed|p|cat)=[^&]+ [NC]
RewriteRule ^wordpress(/.*)?$ http://www.example.co.uk/? [R=301,L,NC]
Make sure this is very first rule in your .htaccess just below RewriteEngine On line.
I'm trying to redirect one URL to another URL. They are different domains, but both have query strings in their URLs. The sample URLs are:
Redirect:
olddomain/faculty/profile?uID=123
to:
newdomain/Faculty?id=024
This is what I've placed in the .htaccess file and it does not work (all modules necessary are installed and activated as there are other 301's without query strings that work without issue):
RewriteCond %{HTTP_HOST} ^www\.olddomain\.tld$ [NC]
RewriteCond %{QUERY_STRING} ^uID=123$ [NC]
RewriteRule ^faculty/profile$ http://newdomain/Faculty?id=024 [R=301,NE,NC,L]
What am I doing wrong?
You need to add http:// also:
RewriteCond %{HTTP_HOST} ^www\.olddomain\.tld$ [NC]
RewriteCond %{QUERY_STRING} ^uID=123$ [NC]
RewriteRule ^faculty/profile$ http://newdomain/Faculty?id=024 [R=301,NE,NC,L]
And make sure this rule is placed at top just below RewriteEngine On.
I have a url that is giving me trouble in terms of a rewrite:
http://www.example.com/my-directory/?image=21
I have tried this:
Redirect 301 /http://www.example.com/my-directory/?image=21 http://www.example.com
Or I know that something along these lines is probably on the right path but I dont think I have the rewrite condition quite right:
RewriteCond %{QUERY_STRING} ^(?image=21)$ [NC]
RewriteRule ^/?$ /? [R=301,L]
Try this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^image=21$ [NC]
RewriteRule ^my-directory/?$ http://www.example.com/? [R=301,L]
I have a strange redirect situation that I cannot get to work.
www.example.com/?NR
www.example.com/?PV
I need to get these two URL's rewritten and redirected to the home page but I can't get it to work. Here is what I have tried:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^NR$ [NC]
RewriteRule www.example.com/ http://www.example.com [R=301,L]
RewriteCond %{QUERY_STRING} ^PV$ [NC]
RewriteRule www.example.com/ http://www.example.com [R=301,L]
We bought this site and I have no reference to what those pages might actually be, they just need to be redirected and rewritten properly.
This one rule should work for both of your requirements:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(NR|PC)$ [NC]
RewriteRule ^/?$ /? [R=301,L]
Remember that RewriteRule only matches REQUEST_URI which is URI part without domain name and query string.
/ in target URI is for your home URL and ? in the end is to strip any existing query string.
Reference: Apache mod_rewrite Introduction