301 Redirect .mp4 file to a link - .htaccess

I have a link to a video file (example.com/abc.mp4), which, when clicked, I would like to redirect to another link. We don't want to change the link on the page since this link was given out, so it would make more sense to redirect it, if possible.
I would think there should be a way to do this via .htaccess and RegEx, but have not been able to have any luck finding a solution, or talk about something like this.
Does anyone have any ideas?

There are two chances: either you're doing the redirection rule wrong, or your Apache is ignoring the .htaccess directives. ¿Do you know if another rewrite rules are working? ¿Can you check if your vhost if configured with AllowOverride All?
Additionally, you could try the following rule to redirect a file which doesn't exist. Just to be sure:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^xyz\.mp4 http://www.newsite.com/newfile.mp4 [r=301,L]
</IfModule>

Related

More than one htaccess rewrite rule

I'm having some trouble understanding .htaccess basically I'm trying to have more than one rewrite rule; for example I have a profile page and then I also want to rewrite the index page so how would this be done; in my previous attempts I could only use one rewrite rule perhaps I was doing something wrong; I have a profile page with the link /profile/profile.php?user=$username and the index page account.php?page=featured how could I get the profile page to look like /account/$username and the account page to look like /account/featured thankyou also how would I then add more later down the line?
the account.php file is in the root directory.
RewriteEngine On
RewriteBase /
RewriteRule ^tag/([^/]+)/([^/]+)$ /tag/index.php?hash=$1&cat=$2
Options All -Indexes
ErrorDocument 403 Denied
that is my current .htaccess which uses the hashtags and shows them like this /tag/$hashtag when I tried to copy and paste this to then use under it it didn't work.
As mentioned in my comment, Apache won't be able to tell which file to rewrite to. So you'll need to change one of the URI structures. As a recommendation, change the one for the profiles.
Here is an example to show you how to do this:
RewriteRule ^tag/([^/]+)/([^/]+)$ /tag/index.php?hash=$1&cat=$2 [L]
RewriteRule ^account/([^/]+) /account.php?page=$1 [L]
RewriteRule ^profile/([^/]+) /profile/profile.php?user=$1 [L]
Remember the [L] flag, which causes rewriting to stop when a match is found.

Pattern Matching htaccess redirect

I know this should be relatively simple but am having trouble and have read and tried several examples from here but none seem to work.
I need to temporarily stop one particular url displaying results and want
to instead redirect the user to another page.
The URL to match on looks like this:
http://www.testdomain.com/news/index.php?toptitle=big%2Bend&XMLFILE=http://anotherdomain/item.rss%3Fkeyword%3Dbig%2Bend
(The URL is longer than the above with more parameters)
But all I want is if the url has: toptitle=big%2Bend in it then I want to redirect the visitor to another subdirectory
Here's what I have tried:
Redirect 301 /(toptitle=big%2Bend)$ /block/
Then I tried:
RedirectMatch 301 ^/(toptitle=big%2Bend)/?$ /block/
I have tried it with and without encoding but doesn't seem to be working so must be doing something wrong.
Other things are working in the htaccess file so am a bit stumped now - any help appreciated.. I know it's basic :-(
Thanks in adavance
How about:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} toptitle=big%2Bend
RewriteRule ^(.*)$ block/? [R=301]
This requires the rewrite module to be enabled in the main config:
LoadModule rewrite_module modules/mod_rewrite.so

htaccess rewrite query string nothing works

THE PROBLEM
After looking at 50+ StackOverflow posts and trying many permutations of my htaccess file, it does nothing still.
WHAT I HAVE TRIED
Using this website to generate my htaccess file: http://www.generateit.net/mod-rewrite/
Setting AllowOverride All in my httpd.conf file and restarting Apache.
MY CURRENT HTACCESS FILE
Lives in the root directory.
RewriteEngine On
RewriteBase /
RewriteRule ^find-a-local-doctor/([^/]*)/([^/]*)$ /find-a-local-doctor/?state=$1&city=$2 [L]
WHAT I WANT TO ACCOMPLISH
Change this URL:
http://www.md1network.com/find-a-local-doctor/?state=FL&city=Tampa
To this:
http://www.md1network.com/find-a-local-doctor/FL/Tampa
ADDITIONALLY
Since the actual file doing the work is: http://www.md1network.com/find-a-local-doctor/index.php, I need to be able to parse the query string with PHP. Hopefully, I will still be able to do this to get the state and city.
Please help.
Thanks.
Your existing rule looks alright but you will need an additional external redirection rule for reverse. Put this rule before your existing rule (just below RewriteBase /).
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(find-a-local-doctor)/(?:index\.php)?\?state=([^&]+)&city=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]

301 redirect rule in htaccess

What am i doing wrong? this rule isn't working
I want the xyz-banking(old) to xyzbanks(new)
RewriteRule ^category/xyz-banking/?$ http://www.domainname.com/category/xyzbanks/ [L,R=301]
When there are multiple categories goes to one new category...can i do this?
RewriteRule ^category/(chicos|chs|rl)/?$ http://www.domain.com/category/apparel/ [L,R=301]
Ofcourse that one is also not working.
Both rewrite rules seem to be correct and they should work.
Whenever you browse to: http://www.domain.com/category/chs/ you will be redirected to http://www.domain.com/category/apparel/ as requested, etc.
Maybe you have a problem somewhere else:
Is mod_rewrite enabled?
Make sure you have RewriteEngine On on your .htaccess or site configuration.
If using an .htaccess file, Make sure you have an AllowOverride directive that allows you to use RewriteRule there.
Try a simple redirect rule first!
Check your error and access logs to see if you can spot any error or warning message.
Take a look at the URL Rewriting Guide - Apache HTTP Server

.htaccess redirect for images from old folder to new folder

I have just moved from Drupal + Wordpress to a site completely built in WordPress.
Duly I have a set of images where the files no longer exist and need to try and keep all the images in the one folder (if possible). Duly I need to send requests for any gif|png|jpg that are for http://www.domain.com/blog/wp-content/uploads/ to http://www.domain.com/wp-content/uploads.
If anyone could help would be appreciated - my .htaccess aint what it once was. Thanks in advance
If you google for "htaccess redirect", the top link is this:
http://www.htaccessredirect.net/
If you use the "301 Redirect Directory" section, you get this code:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) /wp-content/uploads/$1
As far as I know the target domain should be absolute, so the following might work:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) http://www.domain.com/wp-content/uploads/$1
Please try this rule in your .htaccess:
RewriteEngine On
RewriteRule ^/blog/wp-content/uploads/(.+)\.(png|gif|jpg)$ wp-content/uploads/$1.$2 [QSA,L]
Try this
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.domain.com/blog/wp-content/uploads [NC]
RewriteRule .* http://www.domain.com/wp-content/uploads [NC,L]
You could try and put this
RewriteEngine ON
RewriteRule ^/blog/wp-content/(.*)$ http://newdomain.com/wp-content/$1 [R=301,L]
What I have hated about all the re-write rules and redirect options for .htaccess files is they all rely on hardcoding the path (URI) and/or server for the redirect.
The point of the ".htaccess" files it it should be for the current directory! It could be referenced in a number of different ways, installed on different servers in different locations. So trying it down to a specific location for a simple directory rename is illogical.
The solution is to somehow incorporate the current URI (regardless or where the ".htaccess" location) into the result...
This is my current solution for location independent ".htaccess" redirect for a renamed sub-directory, and even I admit it is not perfect... BUT IT WORKS...
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^OLDdir/.*$ %{REQUEST_URI}::: [C]
RewriteRule ^(.*)/OLDdir/(.*)::: $1/NEWdir/$2 [R,L]

Resources