htaccess redirect to url parameter - .htaccess

Is it possible to redirect with htaccess, from
http://example.com/redirect.php?url=http%3A%2F%2Fanother.com%2Fsmiley.gif
to url parameter,
http://another.com/smiley.gif
Please advice.

You can use this :
RewriteEngine on
RewriteCond %{THE_REQUEST} /redirect\.php\?url=.+([^/]+\.gif)\s [NC]
RewriteRule ^ http://another.com/%1? [NE,L,R]
This will redirect /redirect.php?url=foobar/foobar.gif to http://another.com/foobar.gif .

Related

.htaccess URL redirect for sub domain and query pattern

I need to redirect via .htaccess such an URL:
mydomain.com/?c=*
into
sub.mydomain.com/?c=*
For example:
must be redirected
mydomain.com/?c=123&a=1&b=2
into
sub.mydomain.com/?c=123&a=1&b=2
must not be redirected neither
mydomain.com/folder/?c=123&a=1&b=2
nor
mydomain.com/?cb=123&a=1&b=2
My Apache ver 2.4.29.
Thank you.
You can use the following rule
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^c=.*$ [NC]
RewriteRule ^$ http://sub.domain.com/ [L,R]

How to redirect this URL using htaccess?

I want to redirect following URL
http://www.example.com/friends/view.php?l=ka&id=21903
Into this page
http://www.example.com/hello.html
How can I do this using htaccess?
You can use the following rule in htaccess :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/friends/view\.php\?l=ka&id=21903\s [NC]
RewriteRule ^ http://example.com/hello.html? [L,R]

301 redirecting in htaccess for redirecting url

i want to redirect this please guide me
form
http://example.com/babycare/testimonials.php?id=7
to
http://example.com/babycare/testimonial/cat/1
To redirect
http://example.com/babycare/testimonials.php?id=7
to
http://example.com/babycare/testimonial/cat/1
You can use the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /babycare/testimonials\.php\?id=([0-9]+) [NC]
RewriteRule ^ /babycare/testimonial/cat/%1? [L,R]

ModRewrite redirect to url from query string

I have a domain
http://mydomain.com/
And i need redirect from this link
http://mydomain.com/?http://example.com
to
http://example.com
Thanks.
This should work for you:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?(.*)\ HTTP
RewriteRule ^ %2\? [R=301,L]

Remove 'index.php' from url without removing parameters in .htaccess

I have a condition for url redirect like,
www.domain.com/something/anotherthing/index.php
i need the above url to redirect to
www.domain.com/something/anotherthing/
If i go to
www.domain.com/index.php/something/anotherthing
i want to redirect to
www.domain.com/something/anotherthing
i have a redirect htaccess rule for this
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php$1 [NC]
RewriteRule ^ /%1$1 [R=301,L]
But this works for the first condition but in the later it redirect me to the root page. Can anyone please help in this redirection.
Thanks in Advance.
Try something like this:
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
RewriteRule ^ %1/%2 [R=301,L]
That should handle any location of /index.php.

Resources