Mod_rewrite mode Apache URL - apache

I have a url that is
www.mydomain.com/category_result.php?Category_Id=MQ==
and would like to create a way when my user type
www.mydomain.com/Brazil redirect me to the link above
How could I archive this ?
Thanks

To leave the '/Brazil' up in their browser bar, do an internal rewrite (assumes you are adding these rules an httpd.conf and not .htaccess):
RewriteEngine on
RewriteRule ^/Brazil$ /category_result.php?Category_Id=MQ==
To redirect:
RewriteEngine on
RewriteRule ^/Brazil$ http://www.mydomain.com/category_result.php?Category_Id=MQ== [R]
But you don't actually need mod_rewrite to do this operation:
Redirect /Brazil http://www.mydomain.com/category_result.php?Category_Id=MQ==

Related

Redirect with .htaccess but getting old URL as parameter

I want to create a .htaccess file which redirects me from
https://example.net/#UserName to https://example.net/user/index.php?user=UserName, but only when there is the #.
Can someone please help me?
You can use this in your htaccess file:
RewriteEngine On
RewriteRule ^#([^/]+)/?$ https://example.net/user/index.php?user=$1 [L,R]
This will redirect a URL of the form example.com/#foobar to https://example.net/user/index.php?user=foobar changing the URL in browser address bar. However, if you do not want the URL to change, use the following instead
RewriteEngine On
RewriteRule ^#([^/]+)/?$ /user/index.php?user=$1 [L]

.htaccess : how to redirect folder to his subfolder?

I have a web page and his url is http://wwww.example.com/category/door/
But I want to redirect (301) the http://www.example.com/category/ to http://www.example.com/category/door/ because the content of http://www.example.com/category/ is empty.
My rewrite rule is the follow :
RedirectPermanent /category/ /category/door/
But it doesn't work, because the browser redirect http://www.example.com/category/ to http://www.example.com/category/door/door/door/door/door/door/door/door/ infinitely.
An idea ? Thank you.
Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/category/door
RewriteRule ^category/$ /category/door/ [QSA,L,R=301]

Hide the directory in the address bar of the browser

The file .htaccess has this directive:
RedirectMatch permanent ^$ /moby/
When I type the website address into the address bar in the browser: http://mobyx.net/ it appears the directory redirected to: http://mobyx.net/moby/
How to hide the directory?
You are currently doing a redirect (you tell the client to try again on mobyx.net/moby if they go to mobyx.net). What you actually want to do is an internal rewrite. This is invisible to the client. You can use RewriteRule for that. See the documentation for more information.
First make sure that mod_rewrite is enabled in httpd.conf. Then add the following to your .htaccess
RewriteRule ^$ /moby/ [L]
This will internally rewrite http://mobyx.net/ to http://mobyx.net/moby/, but not http://mobyx.net/index.php for example. If you want everything to be rewritten on your site, use:
RewriteCond %{REQUEST_URI} !^/moby
RewriteRule ^(.*)$ /moby/$1 [L]
This will rewrite the url if it doesn't already point to the /moby subdirectory.

Apache redirect localhost to localhost/abc/def/

I want to map "localhost/" to "localhost/abc/def/" in apache. How should I edit .htaccess to achieve this?
If you want to redirect just this one URL, use this simple RewriteRule
RewriteEngine on
RewriteRule ^$ /abc/def/ [R,L]
If you want to move the whole site instead, you can use Redirect
Redirect / /abc/def/

Apache redirect

I would like to redirect a URL using RedirectMatch within Apache eg,
/test/one/?? redirect to /test/two/??
where the ?? represents any string that follows
The redirect i'm using below does a straight redirect but doesnt match any string after...
RedirectMatch Permanent ^/test/one?$ /test/two/
Thanks alot
RewriteEngine ON
RewriteBase /
RewriteRule ^/test/one/(.+)$ /test/two/$1
if that does not work, change ^/test/one into ^test/one
make sure mod_rewrite is enabled
You can use mod_rewrite for this:
RewriteEngine On
RewriteBase /
RewriteRule ^/test/one/(.*) /test/two/$1 [L,R=301]
The R flag redirects the page rather than internally rewriting the URI. 301 is the HTTP status code for "Permanently Moved" - if you'd rather use another, you can change it to one of these.