302 Redirect in htaccess file - .htaccess

I'm trying to temporarily redirect all product pages on my domain to my Etsy shop home page. The code I'm using does redirect, however, it picks up the product title and appends it to the Etsy url.
Redirect 302 /product http://etsy.wileyvalentine.com
Sample URL of a page to redirect:
http://www.wileyvalentine.com/product/apothecary-inspired-marriage-certificate/
Destination page for all:
http://etsy.wileyvalentine.com
Any advice on how to get this to work? Thanks!

The comment above led me in the right path to get to the following code which fixed my problem:
RedirectMatch 302 /product http://wileyvalentine.etsy.com

Use this code
# TEMPORARY PAGE REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine on
RedirectMatch 302 ^/yourpage/?$ http://yourwebsite.com/samplepage/
</IfModule>

Redirect directive matches the full url path, to match against a specific part of the url path , use RedirectMatch
RedirectMatch 302 ^/product/?$ http://etsy.wileyvalentine.com

Related

Capture middle directory and redirect to new url

The URL I'm working with is something like this...
old-website/directory/sub-directory/last-directory
I need to capture just the sub-directory portion and then use that in a URL for a redirect. For example, redirect to new-website/working/sub-directory/page
However, I also need a redirect that works for old-website/directory/sub-directory to redirect to the same new-website/working/sub-directory/page
You can use this RedirectMatch rule in your root .htaccess:
RedirectMatch 302 ^/directory/([^/]+)(?:/.*)?$ http://working/$1/page
Change 302 to 301 once you verify that rule is working fine.

Friendly URL or url-rewriting

I am working on a site that uses such a url
www.domain.com/hotels/hotel-name
I would like visitors just to see
www.domain.com/hotel-name
This can probably be done in the .htaccess file with a rewrite condition but I don't know how.
Thank you for helping
You can use RedirectMatch directive :
Put the following Redirect above other rules in your htaccess file
RedirectMatch 301 ^/hotels/([^/]+)/?$ /$1
This example would redirect all files from the /hotels/ folder, if you want to redirect a particular file from that folder , you can use the following:
RedirectMatch 301 ^/hotels/(file_name)/?$ /$1
Now if a visiter enters www.example.com/hotels/hotel-name then will be externally redirected to www.example.com/hotel-name

Using .htaccess to redirect to a subfolder

I'm trying to 301 redirect from '/en' or '/en/' to '/en/home' using .htaccess, but any attempt I do results into a redirection loop '/en/home/home/home/home/home/home...'.Shouldn't it be as simple as Redirect 301 /en /en/home?
Redirect based rule keep matching /en in redirected URL as well. You can use RedirectMatch for this with regex support:
RedirectMatch 301 ^/(en)/?$ /$1/home
Also make sure to clear your browser cache when you test this.
You have to use the full URL, example:
redirect 301 /folder_wrong/name.html http://website.com/folder-right/name.html

Duplicate pages 301 redirects changing destination url

I have some dupilcate pages in my Joomla site.
Examples
/80-games
/80-games?start=12
/80-games?start=20
I did a 301 redirect in my .htcaccess for the first one which works fine.
My redirect for /80-games
Redirect 301 /80-games http://www.teach-this.com/esl-games
But for /80-games?start=12
The url changes to http://www.teach-this.com/esl-games?start=12
What should my redirect be for /80-games?start=12
Somehow the question mark is causing my destination url to change.
Thanks
Paul
You should use mod_rewrite as you cannot manipulate QUERY_STRING using mod_alias rules.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^80-games/?$ http://www.teach-this.com/esl-games? [R=301,L,NC]
Note ? at the end of target URI that is used to strip out any existing QUERY_STRING in the original URL.

.htaccess to pass FULL URL into other PHP link as $_GET

From .htacces file, how to pass/redirect the FULL URL to another URL as GET Variable?
Like:
http://www.test.com/foo/bar.asp
will be redirected to:
http://www.newsite.com/?url=http://www.test.com/foo/bar.asp
With Full Url with Domain.I tried:
RewriteEngine on
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=%{REQUEST_URI}
But it is going out like:
http://www.newsite.com/?url=?%{REQUEST_URI}
RewriteEngine on
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=$1.asp
If the initial domain and protocol is always the same then you can use
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=http%3A%2F%2Fwww.test.com%2F$1\.asp

Resources