htaccess non permanent redirect (301) - .htaccess

I'm trying to redirect every visitor that tries to enter my homepage (http://www.mysite.com/) to the Pub directory (http://www.mysite.com/Pub/)
I want the url field to show http://www.mysite.com and not http://www.mysite.com/Pub/
I've tried this, but for some reason it doesn't work:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule / /Pub/
Thanks,

The answer is here:
how to mask URL with htaccess?
long story short - it's impossible to show http://www.mysite.com and not http://www.mysite.com/Pub/.
Btw - you mean permanent redirect (301) or non permanent redirect (307)?

Have your rule in .htacess like this:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^/?$ /Pub/ [L]
It is important to not use R flag above so that its an internal redirect only without changing URL in the browser.

Related

URL REWRITING : Redirect a link to the new

I am a beginner in the REWRITING URL and in fact I replaced this link http://www.downisynet.rf.gd/article.php?id=14 with http://www.downisynet.rf.gd/tutoriel/14
Yet both links are still accessible.
So I want to know how to redirect the old URL to the new one?
Here is my .htaccess code:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^tutoriel-([0-9]+) article.php?tutoriel=$1 [L]
Thank you for helping me!
You can simply 301 redirect one page to another using .htaccess. Add the following to your .htaccess file:
RewriteEngine on
Redirect 301 /article.php?id=14 http://www.downisynet.rf.gd/tutoriel/14
Modified rule for /tutoriel/any-digit to /article.php?tutoriel=any-digit
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^tutoriel\/([0-9]+)$ /article.php?tutoriel=$1 [L]

redirecting to a different directory using htaccess

I'm trying to redirect the following
/books/categories/mountain-literature/my-father-frank.html
to
/books/categories/baton-wicks/my-father-frank.html
This is the line in my .htaccess
RedirectMatch 301 /mountain-literature(.*) /books/categories/baton-wicks$1
it rewrites the url and appends this pageUrl stuff on which I don't want and the correct page doesn't load ?
books/categories/baton-wicks/my-father-frank.html?pageUrl=books/categories/mountain-literature/my-father-frank&contentType=html
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^mountain-literature/(.*)$ /baton-wicks/$1 [L,R=301]
try this or this
Redirect 301 /mountain-literature /baton-wicks
If you dont need the rewrite rule to match multiple URL's, try just hardcoding the target URL, i.e.
Options +FollowSymLinks
RewriteEngine On
RewriteRule mountain-literature/(.*) /books/categories/baton-wicks/my-father-frank.html [L,R=301]
By adding the [L] flag it should tell apache not to allow any other rules to append to the URI

htaccess remove part of url and redirect

Trying to eliminate some duplicate urls. Currently I will get links like:
http://www.domain.com/item/2013/05/testing-title-example/catid/175
But its also created as:
http://www.domain.com/item/2013/05/testing-title-example/
I need to simply remove the /catid/# from all urls and be google friendly rewrites/redirects. Any suggestions?
You just need a simple 301 rule like this code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/catid/ /$1 [R=301,L,NC]
R=301 (permanent redirect) will tell search bots to cache the new URL.

.htaccess redirect /shop/ but not /shop/product

I need to redirect from:
/shop/ to /shop/pay-your-bill/
At the moment in my .htaccess file I have:
Redirect /shop/ http://url/shop/pay-your-bill/
This however results in this error:
The web page at URL/shop/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill/pay-your-bill has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Is there a way to redirect shop to pay-your-bill correctly?
Thanks!
You can use RedirectMatch like this:
RedirectMatch 302 ^/shop/?$ /shop/pay-your-bill/
Or if you can use mod_rewrite then use:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^shop/?$ /shop/pay-your-bill/ [L,R,NC]
You can try this
rewriterule ^/shop/(.*) http://url/shop/pay-your-bill/ [r=301,nc]

Possible to change links and redirect with htaccess?

This is my .htaccess
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^genre/(.*)$ /index.php?genre=$1 [R=301]
The mod_rewrite works, but so does the old link example:
/index.php?genre=action
Still works. I want to redirect it to:
/genre/action
Problem: They both work, I want the old one to redirect to the new one.
And is it possible to change links with .htaccess. Some sort of url replacing?
My links still says:
www.site.com/index.php?genre=action
I want it to change it to:
www.site.com/genre/action
Or do I have to do this manually?
Thanks!
[R=301] leads to a HTTP redirect with status code 301.
Just write
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^genre/(.*)$ /index.php?genre=$1
to rewrite the urls on the server side.

Resources