htaccess redirect GET request - .htaccess

I try to redirect some URL with GET request to the new URL with htaccess.
old:
http://example.com/?screenshot=file%20name.jpg
new:
http://example.com/downloader.php?screenshot=file%20name.jpg
I checked similar questions but couldn't handle this.

Add this rule in top of .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} screenshot=(.*)
RewriteRule ^\/$ /downloader.php [QSA,R=301,L]
</IfModule>
or check this modified rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} screenshot=(.*)
RewriteRule ^\/$ /downloader.php?screenshot=%1 [R=301,L]
</IfModule>

Related

htaccess redirect specific subfolder

I'm would like to setup a htaccess HTTP 301 redirect from /abc/* to http://newdomain.com/xyz/*.
I'm trying with this rewrite rule, but it is not working as expected:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/abc/(.*)?$ [NC]
RewriteRule ^ http://newdomain.com/xyz%{REQUEST_URI} [R=301,L]
</IfModule>
It redirect /abc/test to http://newdomain.com/xyz/abc/test. How can I change the rewrite rule to remove the abc part from the request uri?
Change this line :
RewriteRule ^ http://newdomain.com/xyz%{REQUEST_URI} [R=301,L]
to :
RewriteRule ^ http://newdomain.com/xyz/%1 [R=301,L]
Bacuse the %{REQUEST_URI} in the first line including /abc/ so you should seperate it from URI .
your all rules should look like this :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/abc/(.*)?$ [NC]
RewriteRule ^ http://newdomain.com/xyz/%1 [R=301,L]
</IfModule>
So , %1 represent this (.*)? after /abc/ in RewriteCond
You could also summerize this rule like the folwoing :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^abc/(.*)$ http://newdomain.com/xyz/$1 [R=301,L]
</IfModule>
Note: clear browser cache the test

Page redirection with .htaccess

I need to make a target, when the user access, https://www.dominio.com.br/portal/anything be directed to https://www.domain.com.br/blog
Is it possible to do this with .htaccess?
Here is the code I have:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule .* / [R=200,L]
RewriteRule ^portal/([a-z0-9\-]+)/$ ^blog/ [QSA]
</ifModule>
Note: Inside the portal folder, I already have an index.php pointing to blog. This .htaccess would go inside this folder.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^portal/(.*) blog/$1 [L,QSA]
</ifModule>

Rewrite Role does not apply

I have php website and I have created .htaccess file. I have two rules. One for force www and other for permalink.
I want to change following Url
http://www.yatha.tv/play.php?vid=1437&id=1
to
http://www.yatha.tv/1437/1.html
But this rule does not change
RewriteRule ^([^/]*)/([^/]*)\.html$ /play.php?vid=$1&id=$2 [L]
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yatha\.tv$
RewriteRule ^(.*)$ http://www.yatha.tv/$1 [R=301,L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /play.php?vid=$1&id=$2 [L]
</IfModule>

Trouble with .htaccess mod_rewrite

Please can somebody take a look at my .htaccess code to help identify what's wrong.
I am trying to amend all example.php, example.html and example.htm URL's to index.php?filename=example.html
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(index\.php) - [L]
RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]
</IfModule>
When I enter a URL like example.html I'm taken to the default 404 and not index.php
Try:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
I'm not using the apache .hatacces for a while,
But try this one:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^.*/(css|img|js)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?filename=$1&%{QUERY_STRING} [L]
Basically what you need is to be sure that the URL didn't have already index.php. You accomplish it with RewriteCond.
After you redirect all to index.php passing the filename as a parameter.
You can add more exception to the RewriteCond like on this example, all content with /css, /js, /img will not pass to this rule.
You can check this thread: Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests also

Dynamic .htaccess redirect

I'm trying to create an .htaccess redirect so that an folder will redirect to its proper page.
For example... http://example.com/contactus/help.html will redirect to http://example.com/contact-us/help.html or http://example.com/contactus to http://example.com/contact-us
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^example\.com/contactus/(.+)$ [NC]
RewriteRule ^ http://example\.com/contact-us/%1 [R=301,L]
</IfModule>

Resources