I have dozens of redirects from an old page e.g. index.php?mode=1,2,3,0 and I want to get rid of all GET Params because the new page is anyways just plain html.
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} mode=17,0,0,0,0$
RewriteRule (.*) /big-mamas-house/ [R=301,L]
I thought removing (.*) would already do the trick but then the rule is not applied anymore according to:
http://htaccess.madewithlove.be/
Your rule can simplified to:
RewriteCond %{QUERY_STRING} ^mode=17,0,0,0,0$
RewriteRule ^index\.php$ /big-mamas-house/? [R=301,L,NC]
? in the end is needed to strip off any previous query string.
Related
I know with a simple redirect one (Sub-)Domain or Folder to another i can get rid of a string like this
RewriteEngine On
RewriteRule (.*) http://www.domain.tld/? [R=301,L]
I know how to get rid of it when it is a simple file too.
But when it comes to the Rootdomain itself (http://domain.tld/?Stringwhatsoever), i am at a loss here. My last try used a modified version of a redirect I used to redirect files and folders around and that worked pretty nicely and also removed the query, but it ended up in a redirection error.
RewriteRule ^ http://domain.tld/? [L,NC,R=301]
So i have no clue how to get rid of Query Strings at urls without breaking it.
Try this :
RewriteEngine On
RewriteCond %{THE_REQUEST} /\?([^\s]+) [NC]
RewriteRule ^$ http://domain.com/? [NC,R,L]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} (.+) [NC]
RewriteRule ^$ http://domain.com/? [NC,R,L]
Reference :
-https://wiki.apache.org/httpd/RewriteQueryString
This may be a basic question regarding RewriteRule but I just counldn't make it work.
What I want to do is detect urls like:
mydomain/myapp/id/some/random/url.html?param=somethingThatIdoUse
mydomain/myapp/id/other/randomabc/perrito.php?param=somethingThatIdoUse
...
The part that I need to discart is from the /id/[all this]?param=somethingIdoUse and use the param if is possible or send the complete url as param so I can regex to get the param.
And have a rule that detect that /id/ exist and redirect to something like:
mydomain/myapp/other/manageRequest.php?params=somethingThatIdoUse
(the params I could get the whole url and strip it as string is no problem)
As well the application have different modules like:
mydomain/myapp/moduleOne/index.php
mydomain/myapp/moduleTwo/index.php
This have to keep working the same.
As far I've tried some of them like:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET /.*;.* HTTP/
RewriteCond %{QUERY_STRING} !^$
RewriteRule .* http://localhostdev/app/index.php %{REQUEST_URI}? [R=301,L]
RewriteEngine On
RewriteBase /spt/
RewriteCond %{REQUEST_FILENAME} !^id$ [NC]
RewriteRule ^(.*)$ index.php [R=301,L]
RewriteEngine On
RewriteCond %{REQUEST_URI} !/campaings/response\.php$
RewriteRule ^/something/(.*) /other/manageRequest.php? [L]
But nothing seamed to do kind of what I needed.
Thanks in advice
mydomain/myapp/id/some/random/url.html?param=somethingThatIdoUse
Here is an example using the above URL:
RewriteRule ^id/some/random/url.html/? /myapp/other/manageRequest.php [L,NC]
The query will be passed through unchanged to the substitution URL
well actually end up being really basic it worked with:
RewriteRule ^.*id.*$ handleRequest.php [NC,L]
I do get the params as they are sent!
Hey guys I'm having a bit of trouble getting my htaccess to redirect properly and was hoping for some help.
I'm expecting DEV-domain.com?CampID=AB12345 to redirect to
http://DEV-www.domain.com/landing/external-marketing/direct-mail/AB?CampId=AB12345
RewriteCond %{HTTP_HOST} ^DEV-(www\.)?domain\.com [NC]
RewriteCond %{QUERY_STRING} ^CampID=
RewriteRule (\w{2})(\w{5})$ http://DEV-www\.domain\.com/landing/external-marketing/direct-mail/$1?CampId=$1$2 [R=301,L]
Unfortunetly I can't get it working for some reason?
Because the RewriteRule matching is meant for the url path, not query strings. Try this:
RewriteCond %{HTTP_HOST} ^DEV-(www\.)?domain\.com [NC]
RewriteCond %{QUERY_STRING} ^CampID=(\w{2})(\w{5})
RewriteRule .* http://DEV-www.domain.com/landing/external-marketing/direct-mail/%1?CampId=%1%2 [R=301,L]
also you don't need to escape dots . in the target url, only in matching patterns. And be aware that if you decide to make your target url CampID instead of CampId, you need to put in another condition:
RewriteCond %{REQUEST_URI} !^/landing/external-marketing/direct-mail/
to avoid an infinite redirect as a target with CampID would match your RewriteCond rule...
I want to get rid of some query string on my whole website (explicitly facebook shared/like query which usually begin with fb_action).
I thought about using .htaccess to do that.
I want this:
Link 1)
http://example.com/documents/de_desmarais_en_sirois?fb_action_ids=10151430962018298&fb_action_types=og.likes&fb_source=timeline_og&action_object_map={%2210151430962018298%22%3A157643874359578}&action_type_map={%2210151430962018298%22%3A%22og.likes%22}&action_ref_map=[]
to look like:
Link 2)
http://example.com/documents/de_desmarais_en_sirois
In my .htaccess, I added:
RewriteCond %{QUERY_STRING} fb_action
RewriteRule ^(.*) /$1? [R=301,L]
But, when I go on the original link, I am directed to my root folder example.com/pages.php, but I want to keep the first part of the URL which is example.com/documents/de_desmarais_en_sirois. I don't want to go to my root.
What should I modify/do?
I assume you've added those rules to the htaccess file in the /documents/ directory?
You'll need to remove the leading slash in your rule's target and add a rewrite base:
RewriteBase /documents/
RewriteCond %{QUERY_STRING} fb_action
RewriteRule ^(.*) $1? [R=301,L]
The query string match could be improved a bit though:
RewriteCond %{QUERY_STRING} (.*)(^|&)fb_[^&]+(.*)$
RewriteRule ^(.*) $1?%1%2 [R=301,L]
RewriteCond %{QUERY_STRING} (.*)(^|&)action_[^&]+(.*)$
RewriteRule ^(.*) $1?%1%2 [R=301,L]
To remove only the facebook query string parameters, if you have other parameters that you want to preserve.
I got the following url:
127.0.0.1/abc_123456/default/index/index/
Which should be rewritten to:
127.0.0.1/123456/index.php/default/index/index/
So remove abc_ and add index.php after it. Problem is that the digits are variable, but the abc_ isn't.
I had the following rule:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /abc_
RewriteRule ^abc_(.*)/(.*)$ /$1/index.php/$2
But that resulted in the url being rewritten to:
127.0.0.1/123456/default/index/index.php/index/
Seems like I'm almost there, but I can't figure it out.
Thanks in advance
Use this simple rule:
RewriteRule ^abc_([0-9]+)/(.*)$ $1/index.php/$2 [L,NC]
Try
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /abc_([0-9]+)/([^\ \?]+) [NC]
RewriteRule ^ /%1/index.php/%2 [L]
EDIT
However, you are right about the other rule, that's the one giving the error; RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_ RewriteRule ^(.*)$ /index.php/$1 That one is used to rewrite if the page does not contain the /abc_123456/
Add an extra condition to that rule as below
#if not abc_
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /abc_ [NC]
#if not already index.php
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
for example, if you need similar solution, when visited this url:
http://yoursite.com/subpage1/subpage2/?YOURSTRING=blabla
to redirected visitor to
http://yoursite.com/subpage1/subpage2/
then see link - http://stackoverflow.com/a/15680832/2215124