how to rediect form htaccess file? - .htaccess

I want to redirect from http://www.example.com/index.php?abz_xyz to http://www.example.com/abz_xyz with htaccess. I am using this code on my htaccess file Redirect /index.php?abz_xyz http://www.example.com/abz_xyz/ but this is not working kindly please help me

Something like this (my regex may be off)
The [L] means Last, so once the rewrite engine hits that line, it'll redirect immediately if it matches
RewriteEngine On
RewriteRule ^index\.php\?abz_xyz$ /abz_xyz/ [L]

Related

Redirect all urls which contain certain parameters to another url which follows a certain pattern

Unfortunately I didn't get it solved by myself and need to ask for help. I want to redirect all urls which follow a certain pattern (in this case it contains "reviews/category"). These URLs supposed to be redirect to another url which is made up the first one:
http://[product-url]/reviews/category/[category-url]
supposed to be redirect to
http://[product-url].html
Furthermore it shouldn't matter if you call the url with or without www.
Example:
http://example.com/ford-blues/reviews/category/cars supposed to be redirect to http://example.com/ford-blues.html
Any help would be much appreciated.
Following code isn't working
RewriteEngine On
RewriteRule ^reviews/category/?$ $1\.html [R=301,L]
Try:
RedirectMatch 301 ^(.*)/reviews/category/ /$1.html
in the htaccess file in your document root.
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^(.*)/reviews/category/ /$1.html [L,R=301]

How to remove style=xx from url with .htaccess?

Could someone help me with a long time problem? Google is crawling a old style and it's messing up my page indexing.
The url is: http://www.mywebsite.com/forum/viewtopic.php?STYLE=54&f=182&t=3587
What I want to do is to remove "style=54".. is this possible? if so could someone help me with the code?
Try adding these rules to your htaccess file in your document root, above any rules you may already have:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^STYLE=[0-9]+&(.*)$
RewriteRule ^(.*)$ /$1?%1 [L,R=301]
This will redirect the browser to the same URI but with the STYLE=### part removed from the query string. So in your example, the browser would then load:
http://www.mywebsite.com/forum/viewtopic.php?f=182&t=3587

Why doesn't this URL rewrite work?

This is a page on my domain: www.mydomain.com/en/stats.php
I want it to look like this: www.mydomain.com/en/statistics/players
This is pretty simple to accomplish, but for some reason the htaccess code below doesn't work.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/statistics/players stats.php [R=301,L,QSA]
I get a 404 error when I try to open the SEO-friendly version. The page opens fine when I use the regular URL. What am I doing wrong?
The URL might not have a leading slash. Try without or optional slash. Additionally, you must check for the leading en, when you anchor your pattern at the beginning
RewriteRule ^/?en/statistics/players /en/stats.php
What worked in the end is the following:
RewriteRule en/statistics/players en/stats.php [NC,L]
I think it needs to be:
RewriteEngine On
RewriteRule ^en/statistics/players en/stats.php [QSA]
The R=301 means it will perform a redirect instead of a rewrite and try to redirect to /stats.php which doesnt exists I guess.
The L flag means that this is the last rewrite rule that will be processed for this request, which in this case I doubt is what you want. If there are rewrite rules further down for /en/stats.php they wont be processed.

htaccess redirection for joomla page

How to do an htaccess redirection for the following
http://goozga.com/demo/index.php?option=com_content&view=article&id=70
needs to rewrite the above URL to
http://goozga.com/demo/index.php?option=com_content&view=article&id=73
please help me?
Try something like:
RewriteCond %{QUERY_STRING} option=com_content&view=article&id=70$
RewriteRule .* index.php?option=com_content&view=article&id=73 [L]
Note that your question has nothing to do with Joomla but depends on Apache's mod_rewrite instead.
Within Joomla, you can also use the Redirect component. You would just have to add a new redirect rule with the first URL as the source and the second as the destination URL.

htaccess redirect with dynamic variables conflict

I'm working in an old CMS that uses htaccess to rewrite URIs with GET variables into something more user friendly.
RewriteEngine on
RewriteRule ^animals/(.*)/ secondary.php?page=$1
RewriteRule ^animals/(.*) secondary.php?page=$1
which results (correctly) in
http://www.example.com/animals/duck
The problem is I now need to redirect some of those pages to new pages. I've tried:
Redirect 301 /animals/goose http://www.example.com/animals/fowl
The redirect almost works, but it adds "?page=goose" to the end of the rewritten URI:
http://www.example.com/animals/fowl?page=goose
I've tried using RewriteRule as well as RewriteCond, but unfortunatley I'm having no luck. Any help would be immensely appreciated.
Try placing this before the other rules instead of the Redirect statement. R=301 is for the redirect and L signals that the rule in question is the last rule to be processed.
RewriteRule ^animals/goose /animals/fowl [R=301,L]
Also you can easily make the slash (just like any other character) optional with a question mark, instead of having two rules.
RewriteRule ^animals/(.*)/?$ secondary.php?page=$1

Resources