.htaccess rewrite from sub directory to top level domain [closed] - .htaccess

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a domain set up as shop.mydomain.com - however the domain name is changing to just www.mydomain.com
So, all traffic that comes in for shop.mydomain.com, needs to redirect to www.mydomain.com
E.g. shop.mydomain.com/product001.html need to redirect to www.mydomain.com/product001.html
Is this possible with a rewrite rule? All site URLs remain the same, but they now reside on www.mydomain.com as opposed to shop.mydomain.com
Thanks in advance!

Per this article
RewriteCond %{HTTP_HOST} ^shop.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

Related

How to replace www in a website with other words like my, m etc.? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have seen many websites, which don't have www in their URL, they just magically redirect www.example.com to my.example.com.
I am trying to figure it out who it is done, please guide me
As for my.example.com,this is something related to subdomains, from your hosting you can create subdomain for example my.example.com, and you can upload files to the folder assigned to that subdomain.
for www and non www it can be set from hosting also and from .htaccess file.
https://www.keycdn.com/support/popular-htaccess-examples
For example if you add this to .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
you can make redirection
You are confusing the prefix www with subdomains. What you want is to add the subdomain 'my' to the domain name 'example.com'

Redirect Rules for .htaccess File [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What will be the code for these redirects in the .htaccess file?
www.site.com/books/ =====> www.site.com/movies/
www.site.com/books/title/ =====> www.site.com/movies/title.html
If you need to do it as 301 redirect (and assuming your htaccess file is in the root folder), then these rules will do the trick:
RewriteRule ^books/$ http://www.example.com/movies/ [R=301,L]
RewriteRule ^books/title/$ http://www.example.com/movies/title.html [R=301,L]
Replace example.com with your domain name.
Search here in S.O. also. There are countless posts on how to do these redirections.
Edit: For dynamic titles the second rule becomes:
RewriteRule ^books/([^.]+)/$ http://www.example.com/movies/$1\.html [R=301,L]

.htaccess simple redirect not working [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to redirect old internal page to my home page. My .htacess file starts like this:
RewriteEngine On
RewriteBase /
Redirect 301 /int/index.php?m=help https://website.com
Further down I have more rules to force SSL and no "www" and these rules are working fine, but for some reason Redirect directive is being ignored, client can open the page without being redirected.
I suspect it's due to the ?m=help. I would use a RewriteRule like this instead:
RewriteCond %{QUERY_STRING} m=help
RewriteRule index\.php https://website.com? [R=301,L]
Please note:
the ? at the end of the rewritten path is needed to cut off the ?m=help; if you omit it, you'll redirect to https://website.com?m=help
the [R=301,L] means: "redirect to the page" and (L) "stop the rewrite engine after applying this rule", that is, no additional rewriting will be appied to the string https://website.com?

htaccess, folder to folder redirect has some problems [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a problem redirecting a folder to another one.
The rule seems to "work" but it stumble at some point adding some other stuff.
Here an example:
The goal is to redirect traffic from oldfolder (not existing anymore) to newfolder.
www.domain.com/one/oldfolder/year/ --> www.domain.com/one/newfolder/year/
So i set up the following rules (first one for the canonical url):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com" [R=301,L]
RewriteRule ^(.*)/oldfolder/(.*)$ $1/newfolder/$2 [R=301,L]
The problem is that it redirects to:
http://www.domain.com/home/username/public_html/www.domain.com/one/newfolder/year/
Anyone can spot the problem in the rule i wrote?
Thank you very much for your help.
Check your DocumentRoot
Check the Directory directive
Make sure you have RewriteBase / if this .htaccess file is in your document root.

htaccess rewrite image URLs [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
How can i rewrite dynamic image URLs to their original origin?
Example url
/images/products/2658-14732-sergeant-dolly-jacket-olive-full.jpg
Real filename
/images/products/0002658/0014732_full.jpg
I now use a 404 page redirect to a php script but this uses a unneccesary amount of impact on the server and somehow blocks VPNs.
I came this far but can't find out how to add leading zeros.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^images/([a-z_-]+)/([0-9]+)-([0-9]+)-(.+)-([a-z]+).jpg$ /images/$1/$2/$3-$5.jpg [L,QSA]
</IfModule>
Try this:
RewriteRule ^(images)/(products)/([0-9]+)\-([0-9]+)\-(?:.+)\-(full).jpg$ /$1/$2/000$3/00$4_$5.jpg
Do the zero's on these0002658 0014732 numbers change?

Resources