redirect all URLs to domain root with htaccess rewrite - apache

I am trying to get all requests including get variables to redirect to another domain with an htaccess rewrite,
I am trying to redirect all URLs from from my old blog to http://www.passiveincomeidea.com domain root but any URLs with a variable are still passing the variable to the new domain, like this one for example http://mika.lepisto.com/?p=2223
Here is what I have currently:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://www.passiveincomeidea.com/ [L,R=301]
How can I get the rewrite to strip all the variables during the redirect?
Thank you!

Append a question mark at the end of redirected URL:
RewriteRule ^(.*)$ http://www.passiveincomeidea.com/? [L,R=301]
For documentation, search for "Modifying the Query String" in the mod_rewrite documentation.

Related

Redirecting some sub pages to another format page using htaccess

I would like to add 301 redirects to specific type subpage on my site which is hosted on LAMP server.
for example,
example.com/witcher-3-100309/player-count - example.com/witcher-3-100309?tab=player-count
example.com/dota-2-100209/player-count - example.com/dota-2-100209?tab=player-count
example.com/pubg-300100/player-count - example.com/pubg-300100?tab=player-count
Is there any way in htaccess to write a general rule for all these type URLs to redirect correctly instead of individual 301 redirect codes in htaccess.
Thanks in advance.
The following should do it
RewriteEngine on
RewriteCond %{THE_REQUEST} /.+\?=([^\s]+) [NC]
RewriteRule ^.+$ %{REQUEST_URI}?tab=%1 [NE,L,R]
This will redirect /foobar/?q=value to /foobar/?tab=value .
When you sure the rule is working ok you can change the R (Temp Redirect flag) to R=301 to make the redirection permanent.

How to rewrite url and redirect with apache mod rewrite?

I have got url:
ipaddress/panelname/main/index.php
How to rebuild it to
ipaddress/center/index.php
?
ofcourse we can see another pages, not only index.php, but this folders in url we can see forever.
I tryed to do this in .htaccess:
RewriteEngine on
RewriteRule ^center/([^/]+)/?$ panelname/main/$1 [L]
RewriteRule ^/panelname(.*)$ /center$1 [QSA,L,R=301,NC]
Redirect 301 ^/panelname(.*)$ /center$1
but i don't see redirect from panelname to center.
but if i type center all works good (but i don't shure, that it works good by my htaccess or by symlink, which i was created in filesystem)
How to rewrite all to another links and howto see redirect from old links to my new? Thank you.
RewriteRule in directory context (which .htaccess is), does never begin with a slash, because the common prefix is stripped from the matched portion first.
Redirect does match strings, not regex'es. The variant that works on a regex is RedirectMatch. Both only work on absolute URL's (the one beginning with a slash).
You either have to do the following:
RewriteRule ^panelname(.*)$ /center$1 [R,L]
or:
RedirectMatch 302 ^/panelname(.*)$ /center$1
Change [R] to [R=301] once you have tested that EVERYTHING works. If you choose the second option, only change 302 to 301 after testing that everything works.
If you want to show /center/index.php to your visitors and keep a redirect from old URL to this URL then you will need one redirect and one rewrite rule (that you already have).
RewriteEngine on
# external redirect from old URL to new one
RewriteCond %{THE_REQUEST} /panelname/main/(\S+) [NC]
RewriteRule ^ /center/%1 [R=302,L]
# internal forward from new URL to actual one
RewriteRule ^center/([^/]+)/?$ panelname/main/$1 [L]

Opencart 301 Redirects

Having a problem with redirect in a .htaccess file on an Opencart store.
It seems that any URL with /index.php?_route_= isn't getting redirected.
For example, this works:
redirect /old-url-here http://example.com/new-url?
This doesn't:
redirect /index.php?_route_=some-url.asp http://example.com
Any idea or suggestions as to what might get this to work?
You can't match against the query string using mod_alias' Redirect directive. You'll need to use mod_rewrite, and if you use mod_rewrite, you're probably going to want to stop using mod_alias altogether.
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} route=some-url\.asp
RewriteRule ^index\.php$ http://example.com/
Another thing is - apart from Jon's answer - that URLs like index.php?_route_=some-keyword are used/created only internally and only in case you have the SEO turned on. In this case, you click on a link with URL like http://yourstore.com/some-keyword and this URL is rewritten into index.php?_route_=some-keyword.
Therefore you shouldn't be creating URLs like that on your own nor try to redirect from them. If you need to redirect, catch the first SEO URL to redirect it.
We do not know where did you put your changes into the .htaccess file, but if you take a close look at this rewrite rule
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
not only you'll find out it is the last rule there, but it also has this L switch which is telling Apache server that if this rule is matched, do a URL rewrite(, attach the query string [QSA] and) stop matching other rules [L] - this is the Last one.
If you need to redirect only a specific URL, do it the same way as redirect for sitemap.xml is done (for example) and place it before the last rewrite rule:
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
# ...
# your new rule here - while the URL in the link is http://yourstore.com/some-url.asp
RewriteRule ^some-url.aspx$ index.php?route=some-folder/some-controller [L]
# ...
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

url rewrites dynamic urls redirects - Magento

I'm looking for htaccess lines that do the following
Redirect old existing urls to new url (301)
Example
www.example.com/categorya/categoryb/product.htm
TO
www.example.com/product.htm
There can be more category parts, or less, it all has to go to /product.htm (Magento).
Who can help?
Try putting these rules in the htaccess file in your document root, preferably above any rules that you may already have there:
RewriteEngine On
RewriteRule ^(.+)/product.htm$ /product.htm [L,R=301]
Try:
RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^.]+)\.htm$ /$1.htm [L,R=301]

apache .htaccess file https:// redirect ---- rewrite it for subdirectory?

here is my code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This will successfully rewrite everything to https (it will "force" https), if I put it in my home directory's .htaccess file. However, what about if I only want my subdirectory of /support to force https? How to rewrite the above code?
The intent is with regards to forcing https in WHMCS
Thanks in advance!
If you want to redirect only a subfolder and not a subdomain, that is even easier. To redirect the subfolder /support/ you would use the following code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/support/(.*)$ https://%{HTTP_HOST}/support/$1 [QSA]
I added a QSA flag, which will force any query string that was entered to be appended to the redirect URL. If you don't use query strings in this section of the site, you can remove that flag. Also, if the string as shown doesn't work, you can try removing the leading slash from the RewriteRule and retrying it.
Add the following rule before the %{HTTPS} line:
RewriteCond %{HTTP_HOST} ^support.domain.com$
This will only allow the rule to execute if the visitor is coming from the subdomain. Please note, these rules will likely need to be put in the .htaccess file that is the root for the subdomain, not the main site root folder.