Rewrite url with query string in htaccess - .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

Related

Redirect URL changing QUERY string parameter ? to & with .htaccess

I am trying to change this url:
http://blabla.nl/download/?url=https://www.bla.com/see?v=345345&type=download
to this:
http://blabla.nl/download/?url=https://www.bla.com/see&v=345345&type=download
Using .htaccess
so the ? needs to change to an &.
at the moment i am not very succesfull fixing this.
You have to do it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(url=https://www\.youtube\.com/watch)\?(v=[A-Za-z0-9]+&type=downloa‌​d)
RewriteRule ^/?8/downloadff/?$ /8/downloadff/?%1&%2 [R=301,NC,L]
I assume that the number 345345 is always a number an will be different all the times but the rest keeps the same.
Put this as .htaccess file on http://example.nl/ or http://example.nl/download/
Try this:
RewriteEngine On
RewriteRule ^download/?url=https://www.bla.com/see&v=345345&type=download/?$ download/?url=https://www.bla.com/see?v=345345&type=download [NC,L]
I hope it works for you.

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.

Simple Htaccess redirect not working

For some reason this is not working...
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url
I have no idea why... If I replace the URL being redirected with another non-existent one (/helloworld) it redirects fine to the new url..
Is it catching on something? I tried escaping (/modules.php\?name=News&file=article&sid=179) but it didn't make any difference, still just 404s.
any help is appreciated!
You can't match against the query string in the Redirect directive, you'll have to use mod_rewrite and the %{QUERY_STRING} variable. Try this:
RewriteCond %{QUERY_STRING} name=News&file=article&sid=179
RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]
# There is a ? here to prevent query strings appending -----^

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]

.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