I would like to know how to create a vanity url for a website.
Ideally I would like to be able to put this on a flyer:
www.charity.org.uk/monthlydonation
and when that is entered, it will go off to:
www.charity.org.uk/donate/monthly-donation.php
I've been reading about vanity urls, redirects and rewrites but quite frankly I'm not even sure what I need to do this?
I tried the following in a .htaccess file:
RewriteEngine On
RewriteBase /
RedirectMatch 301 /monthlydonation /donate/monthly-donation.php
but got an error message saying there was a redirect loop.
All time and help is greatly appreciated.
Try using mod_rewrite instead, RedirectMatch is part of mod_alias and processes the request separate from mod_rewrite:
RewriteEngine On
RewriteBase /
RewriteRule ^monthlydonation$ /donate/monthly-donation.php [L]
Additionally, the reason why you're getting a redirect loop is that RedirectMatch expects a regex and not just a path. So /monthlydonation is the matching pattern, and that happens to also match the redirect's target: "/donate /monthly-donation.php".
Related
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
I am cleaning up some old stuff and I need to do some 301 redirects.
For example:
I have following absolute url: http://mysite.dk/product.asp?product=371&sub=0&page=1
That i need to redirect to:
http://mysite.dk/category/test
I have tried with htaccess:
RedirectMatch 301 /product.asp?product=371&sub=0&page=1 /category/test
But above code will not work, It is showing the 404 page and ignoring the redirect I just made. Note please that product.asp does not exists as a file!
However if I use:
RedirectMatch 301 /product.asp /category/test/
It works sort off, but now I can't do redirects, based on the query string for that specific file.
Any suggestions? Btw I am using Prestashop=)
Best, Simon
You cannot match query string using RedirectMatch directive. Use mod_rewrite rule instead:
RewriteEngine On
RewriteCond %{QUERY_STRING} product=371&sub=0&page=1
RewriteRule ^product\.asp$ /category/test/? [L,NC,R=301]
? in the target is to strip off existing query string.
mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.
from here
Just add the rules from #anubhava answer into Prestashop .htaccess and it will works. Better to do it before # ~~start~~ line, you will see notice in the file.
What will be a 301 redirect rule using htaccess to redirect urls similar to
domain.com/community/783-anystring-string/profile
to
domain.com/community/
or
any url matching this type of format
domain.com/community/123-anystring-string/...
to
domain.com/community/
Basically I want to redirect any urls domain.com/community/(starting with numbers)-string...
to domain.com/community/
You'll want to use mod_rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^community/[0-9]* /community [R=301,L]
I think. That may not work, I can't test it right now :/
I bought an old site that apparently used some kind of a CMS, maybe wordpress.
Now it's a simple html site. I want to redirect www.example.com/main and everything in that directory to root. In other words, if a url is example.com/main/a_bunch_of_garbage that should 301 redirect to the homepage. Here is what I have but it doesn't quite work.
Options +FollowSymLinks
RewriteEngine on
RedirectMatch 301 ^/main/(.*)$ http://www.example.com
If the url doesn't contain any weird characters like ? or = then it works. But for example, if I go to www.example.com/main/index.php?option=com_content&view=post&id=84&Itemid=982/
Then although it does redirect to the homepage, in the address bar, I still see the entire URL. Can I fix this?
I also just remembered another problem I had. If I put example.com/main (without forward slash after main) the redirect doesn't work. It only works if I put example.com/main/ (with forward slash)
You need to use mod_rewrite rules only and avoid mixing RedirectMatch here. Have your rules like this in your root .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^main(/.*)$ $1? [L,NC,R=301]
? in the end is used to strip off any existing query string.
I don't know much about .htaccess, but I'm trying to help a friend who recently moved his blog to Wordpress.
We need to redirect the OLD archive pages like this:
www.domain.com/2010_04_01_archive.html
www.domain.com/2010_04_02_archive.html
www.domain.com/2010_04_03_archive.html
to NEW archive pages like this:
www.domain.com/2010/04/01
www.domain.com/2010/04/02
www.domain.com/2010/04/03
I've tried everything I can find using htaccess redirect and rewrite, but again, I don't really know what I'm doing with htaccess!
Thanks so much for your help,
Amanda
OK tried this:
Turn mod_rewrite on
RewriteEngine On
RewriteRule ^([0-9]{4})([0-9]{2})([0-9]{2})_archive.html$ /$1/$2/$3 [L,R=301]
in .htaccess in the very top level folder of my site. Still, when I go to http://www.bikermetric.com/2010_04_01_archive.html, it doesn't redirect.
Just tried this too:
RedirectMatch 301 ^/([0-9]{4})([0-9]{2})([0-9]{2})_archive.html$ /$1/$2/$3
Still nothing.
You can use mod_alias or mod_rewrite here. You'll want to stick with using mod_rewrite if you already have rewrite rules (stuff that look like RewriteEngine or RewriteRule):
mod_alias:
RedirectMatch 301 ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3
mod_rewrite:
RewriteEngine On
RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3 [L,R=301]
You'd want to add it to the htaccess file in your document root.