RedirectMatch not working - mod-rewrite

I have this URL:
http://www.example.com/prospective/deginfo.php?classname=PE&diploma_description=BSc+in+Mathematical+Sciences
That I need to redirect to this URL instead:
http://www.example.ie/prospective/deginfo.php?classname=PEC&diploma_description=BSc+in+Mathematical+Sciences+with+French+%27Bachelor+Honours+Degree%27
I thought I could do the following with a RedirectMatch to "catch" everything up to Bsc and from there get it to redirect to the URL I want but it is not working :
RedirectMatch ^/.*BSc\+in\+Physical\+Education http://www.example.ie/prospective/deginfo.php?classname=PEC&degree_description=BSc+in+Mathematical+Sciences+with+French+%27Bachelor+Honours+Degree%27
Can anyone advise what I'm doing wrong and how to correct please?

You can't match against the query string in a RedirectMatch, it only matches against the URI. You can match against it using mod_rewrite and a RewriteCond:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^classname=PE&diploma_description=BSc\+in\+Mathematical\+Sciences$
RewriteRule ^/?prospective/deginfo.php$ /prospective/deginfo.php?classname=PEC&degree_description=BSc+in+Mathematical+Sciences+with+French+'Bachelor+Honours+Degree' [L,R]

Related

ISAPI Rewrite : Append querystring to the rewrited URl's Query String

Actually, using the following ISAPI rule
RewriteCond %{HTTP:Host} ^domain.com$
RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx [NC,L]
I'm rewriting the following URL
htttp://www.domain.com/Product-name/
to
htttp://www.domain.com/test.cfm?ProducID=xxxx
This is working fine, But when I use the querystring in URL, it is not working
For Egs:
The following URL is not working
htttp://www.domain.com/Product-name?categoryID=YYYY
I need to rewrite the above URL as follows
htttp://www.domain.com/test.cfm?ProducID=xxxx&categoryID=YYYY
I've used the following rule, but no luck
RewriteCond %{QUERY_STRING} ^param=(\d+)$ [NC]
RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx?param2=%1? [NC,L]
So is there any solution for this?
If you are using ISAPI_Rewrite 3, then you should add QSA flag to append original query string to the resulting URL:
RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx [NC,L,QSA]
The following rule, appends the query string to the rewritten URL's Querystring and avoids the 404 error
URL With Querystring and Trailing slash(/)
RewriteRule ^/Product-name/\? /test.cfm?ProductID=xxxx [NC,L,QSA]
URL With Querystring and Without Trailing slash(/)
RewriteRule ^/Product-name\? /test.cfm?ProductID=xxxx [NC,L,QSA]
URL Without Querystring and with Trailing slash(/)
RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx [NC,L]
URL Without Querystring and Trailing slash(/)
RewriteRule ^/Product-name$ /test.cfm?ProductID=xxxx [NC,L]

mod_rewrite pattern to handle a page with parameters

i'm really unable to understand how to handle this..
I have this URL: mywebsite.com/product_search.aspx?area=6&category=46
i want to redirect all request to
mywebsite.com
i have tried something like: RewriteRule ^product_search.aspx(.*)$ / [L] and RewriteRule ^product_search.aspx([^/]+)$ / [L], but they are not working or redirect the page to mywebsite.com/area=6&category=46
Anyone can help me ?
Thanks.
As my comment above, .aspx is on Windows, mod-rewrite is an apache module, are you using apache in Windows?
This will be a first approach for apache server, instructions to be inserted in .htaccess or vhosts or equivalent:
RewriteEngine On
RewriteRule ^product_search\.aspx$ / [R=301,L]
It performs a redirection like this:
mywebsite.com/product_search.aspx?area=6&category=46
=> mywebsite.com/?area=6&category=46
Go get rid of all URL arguments, you can append ? at the end of the result URL:
RewriteEngine On
RewriteRule ^product_search\.aspx$ /? [R=301,L]

301 redirect for a query string with space to a non dynamic URL

What is the best way to redirect a specific page that has a space in query string to a name page? I have tried the following which doesn't seem to work:
Redirect 301 "/user.php?name=user name" /users/list
As the discussion in comments, neither Redirect nor RedirectMatch allow us to specify a query string for the redirect source, like this:
Redirect 301 /user.php?name=user%20name /users/list # this does not work!!!
We should deploy the powerful machine of RewriteEngine even for so little, in /.htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} name=user%20name [NC]
RewriteRule ^user\.php /users/list [R=301,NE,L]

Redirect URL with htaccess

A third party plugin returns to an incorrect URL from a call to save a change.
The URL is /admin/?page=configure/admin/. The correct return should be to /lists/admin/?page=configure. My attempt to write a redirect failed with a 500 server error.
RewriteEngine On
RewriteRule ^(.*)/admin/(.*)$ $1/lists/admin/$2 [NC,L]
How can I correct this code?
This should work.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^lists
RewriteRule ^(.*/)?admin/(.*)$ $1lists/admin/$2 [QSA,L]
If you want to match a different folder to redirect to admin you will have to declare it literally as a pattern like ^(.*)?/admin would also match lists/admin and cause a loop.

rewriting single url help

I'm trying to rewrite the following url:
index.php?route=checkout/cart
to
/cart
using:
RewriteRule ^index.php?route=checkout/cart$ /basket [L]
However it doesn't seem to work. Anyone know what I'm doing wrong?
Thanks
RewriteRule does only test the URL path. You need RewriteCond to test the query:
RewriteCond %{QUERY_STRING} ^route=checkout/cart$
RewriteRule ^index\.php$ /basket [L,R=301]
The additional R=301 flag will cause an external redirect with the status code 301 (permanent redirect) instead of an internal redirect.
And if you want the other way round:
RewriteRule ^basket$ index.php?route=checkout/cart [L]
You need to send a redirect so that the new URL get reflected in browser address bar. So, add R to the [L].
RewriteRule ^index.php?route=checkout/cart$ /basket [R,L]
If you'd like that searchbots should ignore the "ugly" URL and/or remove it from the indexes and use the new instead, then send a 301 redirect.
RewriteRule ^index.php?route=checkout/cart$ /basket [R=301,L]

Resources