I want to redirect "adm" folder to "administrator"
my .htaccess code:
Redirect 301 /adm /administrator
But i go to the url:
http://www.mywebsite.com/home2/myuser/public_html/administrator
How to do this correctly?
Can RewriteRule with flags [R=301,L] do the work? Because I go to the same page with RewriteRule or Redirect
Thanks.
So this may not be a problem of your rewrite rules but maybe something wrong about your configuration.
Anyway try a rewriterule like this:
RewriteRule ^/adm(/(.*))$ /administrator$1 [QSA,R=301,NC,L]
RedirectMatch directive would do
RedirectMatch permanent /adm(.*)$ http://www.mywebsite.com/administrator$1
Related
I would like to make a redirect using htaccess rules to point ALL links from
mywebsite.com/subfolder1/subfolder2/...whatever-path....
to
mywebsite.com/subfolder1
But the problem is that whatever rule I use it always keeps the old path in the destination link, for example:
mywebsite.com/subfolder1/subfolder2/mypage.php
becomes
mywebsite.com/subfolder1/mypage.php
I tried all the following possibilities:
RewriteRule (.*) https://mywebsite.com/subfolder1/$1 [R=301,L]
RewriteRule ^subfolder1/subfolder2/(.*)$ /subfolder1/$1 [R=301,NC,L]
RewriteRule ^/subfolder1/subfolder2/(.*)$ /subfolder1/$1 [R=301,NC,L]
Redirect 301 /subfolder1/subfolder2 https://mywebsite.com/subfolder1
RedirectMatch 301 /subfolder1/subfolder2(.*)$ /subfolder1/$1
RedirectMatch 301 ^/subfolder1/subfolder2/?$ https://mywebsite.com/subfolder1
I have placed the "Options +FollowSymLinks" and "RewriteEngine on" rules before them, but NONE of them worked.
Can someone tell what's wrong and how to find the right rule?
Thank you.
Try this
RewriteRule ^subfolder1/subfolder2/(.*)$ /subfolder1 [R=301,NC,L]
With $1you attach the content of (.*) to the redirected URL. Remove them from code and
http://mywebsite.com/subfolder1/subfolder2/whatever-path
will be
http://mywebsite.com/subfolder1
I'm trying to redirect http://domain.com/search to http://domain.com
However I also have urls that looks like http://domain.com/search?q=someword
At the moment I have :
redirectMatch 301 http://domain.com/search$ http://domain.com
And even though it redirects correctly the http://domain.com/search url, it also redirects any http://domain.com/search?q=someword url to http://domain.com/?q=someword, which I do not want.
What am I doing wrong?
I would suggest you to use mod_rewrite instead of mod_alias in your htaccess :
RewriteEngine On
RewriteBase /
RewriteRule ^search/?$ / [L,R=301]
Add a ? to the end of your target:
RedirectMatch 301 ^/search$ http://domain.com/?
This, however, will cause a ? to appear at the end of the URL in the browser's location bar. If you use mod_rewrite instead, you won't see the ?:
RewriteEngine On
RewriteRule ^/?search$ /? [L,R=301]
I need to redirect a dynamic url to another url, with the dynamic portion intact, for example:
http://www.mydomain.com/VARHome.aspx?var=32
needs to redirect to:
To: http://www.otherdomain.com/VARHome.aspx?var=32
The value after "var=" is dynamic, it can be any number.
This needs to be done via .htaccess.
Thanks for any help!
I'm thinking RewriteRule ^(.*)$ http://www.otherdomain.com/$1 [R=301,L] or something along those lines should do the job.
Edit: Maybe something like
RewriteRule ^VARHome.aspx?var=(.*)?$ http://www.otherdomain.org/VARHome.aspx?var=$1/ [R=301,L]
if you are in mydomain.com, write in .htaccess
RewriteEngine on
RedirectMatch 301 ^/VARHome.aspx?var=(.*)$ http://www.otherdomain.com/VARHome.aspx?var=$1
I am creating htaccess for my site I need to redirect old urls to new url through 301 redirect. I have created code in htaccess as follows
My old urls like
www.example.com/categories/city/cityname/brandname/product1.html
and my new url is like
www.example.com/product1.html
For this scenario I have written following code in htaccess
RedirectMatch 301 ^/categories/city/cityname/(.*)$ http://www.example.com/$1
Please help me regarding this scenario or where I am doing wrong.
Try using mod_rewrite's functionality in your .htaccess like this:
RewriteEngine On
RewriteRule ^/categories/city/cityname/(.*)$ /$1 [R=301,L]
Referring to #Seybsen answer, this 1 line should fit all your needs :
RewriteRule ^/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/(.*)$ /$5 [R=301,L]
I'm trying to use mod_rewrite to redirect URLs and can't get anything to work. Here is what I'm hoping to do:
Old URL:
http://www.example.com/asp.pl?_puri=astore.amazon.com%2Fthegi02-20%2Fdetail%2FB0001L0DFA%2Fassid
Needs to redirect to:
www.example.com
Anyone know of any way to do that?
Redirect and all the other Redirect* directives do only work with the URL path. So you cannot test the query.
But with mod_rewrite you can:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^_puri=astore.amazon.com&thegi02-20&detail&B0001L0DFA&assid$
RewriteRule ^asp\.pl$ http://www.example.com/ [L,R=301]