htaccess remove part of url and redirect - .htaccess

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.

Related

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

How to redirect urls starting with numbers

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 :/

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.

htaccess non permanent redirect (301)

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.

How to redirect these old urls to new ones (subfolder) via htaccess

I am a newbie and would like to redirect all my old urls to new ones (moved as subfolder) via htaccess. Also, with 301 permanent redirect.
Old url pattern looks like:
http://www.mydomain.com/de/myoldpage.html
New url pattern should be:
http://www.mydomain.com/shop/de/myoldpage.html
I am using the same domain and same page urls but only my shop is moved to a subfolder "shop".
How can i write a redirect rule to redirect all the urls in this pattern.
Thanks in advance.
Try this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^(de/.*)$ /shop/$1 [L,R=301,NC]
RewriteEngine On
RewriteRule ^de/(.*)$ shop/de/$1 [L,R]

Resources