How to setup .htaccess rewrite url - apache

how do I setup a redirect as follows:
Redirect these:
http://www.domain.com.au/browse-stores/storeA
http://www.domain.com.au/browse-stores/storeB
To these
http://www.domain.com.au/browse-stores?centre=storeA
http://www.domain.com.au/browse-stores?centre=storeB

Put this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^browse-stores/(.+)$ /browser-stores?centre=$1 [L,QSA]
If you actually wanted to redirect the browser so that the URL in the address bar changes, change the flags in the brackets to [L,QSA,R=301].

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 from root to subfolder?

I have a website with URL www.somedomain.com
I want to redirect to a subfolder "folder", so that when you enter the website you are automatically redirected to www.somedomain.com/subfolder.
But I do not want the root directory to be changed, just simple redirection.
Is this possible with .htaccess ?
Is it possible to hide the /subfolder part from the URL also ?
Thanks
You can use a rewrite rule that uses ^$ to represent the root and rewrite that to your /store directory, like this:
RewriteEngine On
RewriteRule ^$ /store [L]
Just replace store with your directory

Mod_rewrite mode Apache URL

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==

htaccess mod_rewrite URL within subfolder

My question seems to be unanswered on StackOverflow, so here goes:
I want to rewrite the following URL using an htaccess file which is in the root folder.
The URL to rewrite is this:
http://www.domain.com/subfolder/item/12345
to this:
http://www.domain.com/subfolder/item.php?id=12345
However nothing I seem to do works. I can successfully rewrite the item.php URL if it is in the root folder using this:
RewriteRule ^item/(.*)$ item.php?id=$1 [NC,L]
... but not if the item.php file is in a subfolder!
You can use following .htaccess in your subfolder:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /subfolder
RewriteRule ^item/(.*)$ item.php?id=$1 [NC,L,QSA]
Your rewritten URL would become: http://domain.com/subfolder/item/123
Here is an example for sending this URL (The one entered in the browser address bar):
http://www.domain.com/subfolder/item/12345 (Can be any number) to this rewrited URL:
http://www.domain.com/subfolder/item.php?id=12345
RewriteEngine on
RewriteRule ^subfolder/item/([0-9]+)/?$ subfolder/item.php?id=$1 [L]
Those directives will work only if there is a subfolder directory and in that directory there is in fact a file item.php

How can I use mod_rewrite to redirect to a "key word" folder

It is hard to explain in title.
I want to make the following two URLs
http://www.example.com/apps/web/admin/images/pic.jpg
http://www.example.com/apps/web/blog/comment/images/pic.jpg
both redirect to
http://www.example.com/apps/view/images/pic.jpg
I put the ".htaccess" file in /apps/ folder.
No matter what is the current URL,
as long as the current URL contain the "images/",
all redirect to this folder
http://www.example.com/apps/view/images
this is my code but it cannot work
RewriteEngine On
RewriteRule ^(.*)/images/(.*)$ views/images/$2
so, how can I set the .htaccess file?
Try:
RewriteEngine On
RewriteBase /apps/
RewriteCond %{REQUEST_URI} !/view/images/
RewriteRule images/(.*)$ view/images/$1 [L]
If you actually want to redirect the browser, as in changing the URL in the address bar, change the L in the brackets to L,R=301