I need a fancy htaccess rewrite to query string - .htaccess

I need a rewrite for htaccess that will take this sample url and rewrite it to the homepage and get rid of the query string.
Example:
Rewrite this:
http://www.domain.com/e-newsletters/forward/49.html?key=BkPOBo4l&tmpl=component
to this:
http://www.domain.com/
Here are the "variables" in the url:
49.html there could be any number.html
?key=BkPOBo4l - the string "BkPOBo4l" will change
&tmpl=component will not change
Any help would be greatly appreciated.

To redirect
http://www.domain.com/e-newsletters/forward/49.html?key=BkPOBo4l&tmpl=component
to http://www.domain.com/
You can use the following :
RewriteEngine on
RewriteCond %{THE_REQUEST} /e-newsletters/forward/[0-9]+\.html\?key=.+&tmpl=component [NC]
RewriteRule ^ http://www.domain.com/? [L,R]

Related

Redirect Dynamic URL with questionmark and ampersand?

I have redirect dynamic URL's which I'd like to redirect (301).
Link type 1
OLD - /?mainPage=Contact
NEW - /Contact
Link type 2
OLD - /?mainPage=Shows&show=circus
NEW - /shows/circus
How to do this?
To achieve that URL, you can use the following rule in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?mainPage=$1&show=$2 [L]
Make sure you clear your cache before you test this.
To redirect a URL using a query:
RewriteCond %{QUERY_STRING} mainPage=Optredens&show=petitcirque$
RewriteRule (.*) /shows/le-petit-cirque/? [R=301,L]

htaccess 301 (permanent) redirection

I need help in 301 permanent URL redirection of dynamic URL's
https://www.xyz.co/certificate.php?certify=iso-haccp
should redirect to
https://www.xyz.co/certificate/iso-haccp-certification
I want to do it using .htaccess file because there are so many url's like this, help me guys?
Try this code :
RewriteEngine On
RewriteCond %{QUERY_STRING} ^certify=(.*)$
RewriteRule ^certificate\.php$ /certificate/%1-certification? [R=301]
A literal redirection would look like this:
RewriteBase /
RewriteCond %{QUERY_STRING} certify=(iso-haccp)
RewriteRule (certificate)\.php /$1/%1-certification? [R=301,L]
We're not using ^ or $ in this example around the query string because it can allow for other variables that could be passed. I'm adding a ? to the end of the redirection string to stop the default behavior of query string append.

Ho to make .htacess redirect and keep full url path

Hi i would like ask you about .htacess 301 redirect:
I have many dynamic urls with paths for example like this:
http://www.domain.com/post1.html
http://www.domain.com/post2.html
and i need to redirect it to the same url but with little bit different domain (without WWW):
http://domain.com/post1.html
http://domain.com/post2.html
I have done like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Redirect works, but my normal urls becomes urls with ID's like:
http://domain.com/index.php?id=931
not like it should be:
http://domain.com/post1.html
Any ideas or helo are appreciated.
Thank you.
You have some other rewrite rules happening here obviously, but with what you've given us, you could try adding this before your rules in order to get it to stop processing an URL which has been rewritten as such:
RewriteCond %{QUERY_STRING} id=[0-9]+
RewriteRule ^index.php - [L]

Rewrite url with query string in htaccess

Today I try to rewrite some ugly url in order to be cache by browser! But the problem is that I have multiparameters inside the url. An example is better than a long text :
the actual url with the ? and the & :
http://images.mydomain.com/lib/simple-thumb.php?src=http://google.com&l=180&h=135&zc=1
And I want to use this instead :
http://images.mydomain.com/lib/http://google.com/180/135/1
Should I use the rule below in my .htaccess?
Options +FollowSymLinks
RewriteEngine On
rewritecond %{query_string} ^(.*)$
rewriterule simple-thumb\.php /lib/%1/? [R=301,L]
But not seams to be work...
Thanks for your kind help
Try
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/lib/http\:\/\/google.com/([0-9]+)/([0-9]+)/([0-9]+)$ /lib/simple-thumb.php?src=http://google.com&l=$1&h=$2&zc=$3

.htaccess php to html

sorry for this simple question, however i still cant get my head round using .htaccess
I'm trying to convert:
search.php?s=dvd&page=1
to
/Search/dvd/page1.html
Thanks,
Jack
I think something like:
RewriteRule ^search/([A-Za-z]+)/page([0-9]+)\.html$ search.php?$1&page$2
Should do the trick.
Further reading here: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
you must put your link "/Search/dvd/page1.html" in the page and with htaccess it will convert to the "search.php?s=dvd&page=1" . i hope it be usefull :)
sample correct htaccess code :
RewriteEngine On
RewriteRule Search/(\d+)/page?(\d+)\.html$ search.php?s=$1&page=$2 [NC,L]
If I understand the question OP wants to convert php to html redirection. Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# to match /search.php?s=dvd&page=1
RewriteCond %{QUERY_STRING} ^s=([^&]*)&page=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%1/page%2.html? [R,L,NC]
# to match /search.php?page=12&s=dvd
RewriteCond %{QUERY_STRING} ^page=([^&]*)&s=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%2/page%1.html? [R,L,NC]
R=301 will redirect with https status 301
L will make last rule
NC is for no case comparison
%1 and %2 are the query parameter values
I think you want make clean URI, so if user type url like this:
search/televisi/page4.html
it same as like search.php?s=dvd&page=1
Add this code:
RewriteEngine On
RewriteRule ^search/([a-z]+)/page([1-9]+).html$ search.php?s=$1&page=$2

Resources