.htaccess redirect remove "?_route_=" form URL - .htaccess

I am using .htaccess redirect in my website. I am using those code
Redirect /addgiftmr/widgetjs.aspx https://www.mysite.com/
But when redirect, it is adding extra word. I am getting url as https://www.mysite.com/?route=addgiftmr/widgetjs.aspx
how can I remove ?route=addgiftmr/widgetjs.aspx form link?

Here is how to do it in .htaccess if mod-rewrite is installed. The advantage of mod-rewrite is that it is easier to expand later if you want to use more complex rules.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^addgiftmr/widgetjs.aspx https://www.mysite.com/ [L,R]

Related

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

Drupal 301 redirects

I am doing a set of 301 redirects in Drupal.
I am using a standard method in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
</IfModule>
but the return url ends up with "?q=user" and stops it working. eg:
http://thesitedomain.com/about?q=user/about
I am not great at htaccess redirects (obviously) and I am no Drupal expert at all.
Also, if you know of a comprehensive htaccess rewrite resource I would much appreciate reading hat.
You will need to use mod_rewrite instead to strip out existing query string:
RewriteEngine On
RewriteRule ^user/testimonials/?$ http://thesitedomain.com/testimonials? [L,NC,R=301]
RewriteRule ^user/contact/?$ http://thesitedomain.com/contact? [L,NC,R=301]
Take note of trailing ? in target that strips out existing query string.
I can't speak to drupal, but I know you don't need to enclose those redirects in the <IfModule mod_rewrite.c> tags, since they don't use the RewriteEngine, the below would suffice:
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
Are both urls in the same drupal? Or are you moving from a different site?
I mean:
/user/testimonials
http://thesitedomain.com/testimonials
Maybe what you need is to add an url alias for /user/testimonials like /testimonials
See under admin at /admin/config/search/path in drupal 7.
Using .htaccess file is not a good practice, because, in some updates you have to update the .htaccess file too.
You can try GlobalRedirect module to manage your redirects.

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 rewrite a url to a subdomain

I don't think this is possible, however I would like to ask the community to see if it is.
I have a blog on a subdomain blog.domain.com due to a revamp of the site we are having to use the blog on a trailing domain domain.com/blog this isnt ideal as all our old post permalinks point to the subdomain.
I was therefore wondering if there is a way to use the .htaccess to rewrite domain.com/blog -> blog.domain.com
Any help would be greatly appreciated.
I believe you want to redirect all the traffic from blog.domain.com to domain.com/blog. Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(blog)\.(domain\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [NE,R=302,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

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