Rewriting part of url using .htaccess - apache

I want to rename the following urls
http://xyz.website.com/search/sOrder,dt_pub_date/iOrderType,desc
to
http://xyz.website.com/search/sOrder,dt_pub_date/iOrderType,desc/category,111
and
http://xyz.website.com/index.php?page=search<&item=1&city=2...and so on>
to
http://xyz.website.com/index.php?page=search&sCategory=111<&item=1&city=2...and so on>

for the first redirect, this an quick solution(if the query is static):
RedirectMatch permanent ^/(search/sOrder,dt_pub_date/iOrderType,desc).*$ /search/sOrder,dt_pub_date/iOrderType,desc/category,111
For the second one:
RewriteCond %{QUERY_STRING} ^page=search(.*)$
RewriteRule ^index.php$ /index.php?sCategory=111%1 [R=301,L]
Hope this will helps you.

Related

Rewrite one directory to another .htaccess

I want to automatically redirect http requests to news/images to ../images.
Is that possible with .htaccess?
Thing is: request to www.site.tld/news/images ... should go to www.site.tld/images ...
I have tried:
RewriteEngine On
...
...
RewriteRule (.*)news/images(.*) ../images [R=301,L]
not working.
I have ensured that apache have mod_rewrite.c enabled.
To redirect all requests for /news/images/ to /images/, capture the part after images and use it in the RewriteRule
RewriteRule ^news/images(.*)$ /images$1 [R,L]
When it works as it should, you may replace R with R=301. Never test with R=301.
You can use:
RewriteRule ^www\.site\.tld/news/images$ /www.site.tld/images?&%{QUERY_STRING}
or you can also use:
RewriteCond %{HTTP_HOST} ^www.site.tld/news/images$ [NC]
RewriteRule ^(.*)$ http://www.site.tld/images/$1 [R=301,L]
But as #arkascha said, please do some research first, there are MANY answers to this sort of problem! :) Either way, I hope this helps.

htaccess rewrite

I've rebuilt a site using a CMS and I want to make the old urls point to the new pages. I'm having trouble because the old URL looks like this: ?secc=country_club. For instance, domain.com?secc=country_club.
I would like to either have a rule for each url or have it rewrite the ?secc=country-club to just country-club
This is what I have tried, without any success:
RewriteRule ^secc-([^-]*)$ /?secc=$1 [L]
I think it has something to do with the ? in the url
Also if it helps, I am using joomla and I do have sh404sef.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^secc=(.+)$
RewriteRule ^(.*) %1? [R,L]
This will redirect http://example.com/?secc=MYPAGE to http://example.com/MYPAGE
I think you meant to write '=' after ^secc:
RewriteEngine on
RewriteRule ^?secc=(.*)$ "$1" [QSA]

mod_rewrite: rewrite specific URL

I want to rewrite a specific URL, I'll show an example so you'll understand what I mean.
First, my current rewrite rule:
RewriteRule ^/?([a-zA-Z0-9/-]+)/?$ /index.php [NC,L]
Now I want this URL:
http://example.tld/foobar?test
Rewritten to:
http://example.tld/foobar
Note: only for /foobar?test! E.g. not for /somethingelse?test and also not for /foobar?blah!
Thanks in advance!
EDIT: I realized I want a 301 redirect from /foobar?test to /foobar, not a "traditional" rewrite. Hope that is possible.
RewriteCond %{QUERY_STRING} ^test$
RewriteRule ^/foobar$ /foobar [NC,R=301,L]

Strange 301 redirect problem

I'm trying to redirect all URLs that start with "/?page=" to "/stuff/?page="
I have this in my .htaccess file:
RewriteEngine on
RedirectMatch 301 ^/?page=/(.*)$ http://www.mysite.com/stuff/$1
But it's not working.. What am I doing wrong?
Try this
RewriteRule ^/stuff/?page=$ /?page=/
Remember, you're effectively turning the right (of the space) into the left.
The directives of mod_alias (one of them is RedirectMatch) do only work on the URI path and not the query. If you want to inspect the query, use mod_rewrite instead:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=
RewriteRule ^$ /stuff/ [L,R=301]

Apache rewrite rule with parameters?

I have the following URL:
http://domain.com/index.php?m=feedback&cSubject=My Subject
I want to have a rewrite rule so that the following:
http://domain.com/feedback?Subject=My Subject
maps to the previous url. Heres my rule at the moment:
RewriteRule ^feedback?Subject=(.*)$ index.php?m=feedback&cSubject=$1
Doesn't seem to be working tho! Any ideas?
Query Strings are not parsed by Apache Mod_Rewrite, but there is a workaround. Try this
RewriteRule ^feedback/?$ index.php?m=feedback&c%{QUERY_STRING} [NC,L]
You can use RewriteCond statement to do exactly what you want:
RewriteEngine On
RewriteCond %{QUERY_STRING} Subject=(.*)
RewriteRule ^feedback$ index.php?m=feedback&cSubject=%1 [L]
There seems to be an = missing from clops answer to give..
RewriteRule ^feedback/?$ index.php?m=feedback&c=%{QUERY_STRING} [NC,L]
.. at least I need one to make it work.