I have a single domain, multi store setup on magento 2.3
For example
example.com/jp/
example.com/uk/
however the sitemaps get generated to their store folders within a sitemaps folder in the root dir, such
example.com/sitemaps/jp/sitemap.xml
My google webmaster domains are setup as such
example.com/jp/
So when I need to submit a sitemap it needs to be example.com/jp/sitemap.xml
I've used
#Sitemap: Japan http://www.example.com/sitemaps/jp/sitemap.xml
RewriteCond %{HTTP_HOST} ^.*example\.com$
RewriteRule ^sitemap.xml$ sitemaps/jp/sitemap.xml [NC,L,R=301]
When I access example.com/jp/sitemap.xml its a 404
I'd like example.com/jp/sitemap.xml to redirect to example.com/sitemaps/jp/sitemap.xml
Is there a way of doing this through .htaccess?
You can use this rule as topmost rule in site root .htaccess:
RewriteEngine On
RewriteRule ^[a-z]{2}/sitemap\.xml$ /sitemaps/$0 [L,NC,R=301]
Make sure there is no other .htaccess and this rule is top most rule.
Related
I have a folder export that is accessible to all my subdomains:
/export/sub1/...
/export/sub2/...
/export/sub3/...
Right now, regardless of what subdomain you're on, you can see all of the content by changing the directory in the url.
It's not a security issue, but more of a canonicalization concern, but I'd like to use an .htaccess file to rewrite the folders so people see a modified path that matches up with their subdomain:
sub1.domain.tld/export/... is served from /export/sub1/...
sub2.domain.tld/export/... is served from /export/sub2/...
sub3.domain.tld/export/... is served from /export/sub3/...
How can I do this?
You can use this generic rule in site root .htaccess:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+) [NC]
RewriteRule ^/?export/(.*)$ /export/%1/$1 [L,NC]
Is it possible to use .htaccess to transparently rewrite a subdomain to show the content of the root domain while making the subdomain name available in the query string?
For example:
https://sub.example.com/
transparently shows the content of:
https://www.example.com/?sd=sub
Another example:
https://sub.example.com/page.php?a=1&b=2
transparently shows the content of:
https://www.example.com/page.php?a=1&b=2&sd=sub
I've tried multiple solutions and so far this is the closest I've gotten:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ https://www\.example\.com?sd=%1 [QSA,L]
The only issue is that it redirects instead of rewriting. As you can see, I am not using the [R] flag so I don't understand why it redirects unfortunately. Also, I need to have the subdomain created in the hosting account for it to work...for example: https://test.example.com redirects to https://www.example.com?sd=test with the .htaccess above and that rewritten URL is shown to the visitor. I also have to have the subdomain test.example.com created in the server for this to function.
I've dug around without much luck finding a solution.
I have a WordPress MultiSite using sub-directories as "temp" URLs so clients can review prior to mapping their domain name.
The login for the mapped domains is domain.com/ui which works with a redirect in my htaccess.
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^ui$ /wp-login.php? [R=301,NE,NC,L]
I've also tried this RewriteRule ^ui(.*)$ /wp-login.php [L,R=301]
However, when attempting to login to a temp URL as described above it does not redirect.
I would like a solution that disregards sub-directories and for that matter any permalink structure and redirects /ui to /wp-login.php
Here are a few examples.
http://adopttheweb.com/ui
http://iemajen.com/emajenwebservices/ui
These are both on the same MultiSite blog. The first has been mapped to a domain whereas the second has not and is simply running at a "sub-directory" of the root / parent site.
Put the following code at main directory .htaccess file
RewriteEngine On
RewriteRule ^ui(.*)$ /wp-login.php [L,R=301]
You can also do it by PHP by putting header('Location: path/to/target.php'); at the ui directory index page etc
I'm trying to organise my websites with .htaccess, and I want to following configuration:
The URL of the main site has to be beta.example.com/portal/
The other sites should be in beta.example.com/othersite/
If users go to beta.example.com, they should be redirected 301 to
beta.example.com/portal/
beta.example.com/portal (without the trailing slash) should redirect to beta.example.com/portal/
/portal/ is not a physical file path on the server. I want all these sites to
be in a folder together, say /html/www/websites/
The folder the portal resides in, should not be located in
/html/www/websites/portal/, but I want to be able to switch the live
site to a new version (in a different folder) on the server, quickly,
invisible, without any downtime. This goes for all sites by the way.
I'm currently working with two or three .htaccess files: one in the root (www.), which directs beta.example.com to the folder /websites/
#RewriteBase / #should I use rewritebase or not?
/RewriteCond %{HTTP_HOST} ^beta.example.com$
RewriteRule (.*) websites/$1 [L,NC]
A .htaccess file is in the folder /websites/, and maybe another one or maybe not in the folder a site resides in.
RewriteBase /websites # or, not...
# rewrite the active site to the folder /portal_v1.0/
RewriteCond %{REQUEST_URI} ^/portal/
RewriteRule (.*) portal_v1.0/$1 [L]
# rewrite the root to /portal/
RewriteRule ^$ http://beta.example.com/portal/ [L,NC]
However, I still can't get this to work exactly the way I want. One problem is what beta.example.com/portal redirects to www.example.com/websites/portal/ , I don't want that. Help! Thanks in advance!
I made simple web page at http://www.domain.com/mobile/{rest of url}
and i want to have http://mobile.domain.com/{rest of url}
On other forums, ppl tolde me to move page, unfortunately it's not possible since that page is using other controllers and models from the rest of page and /mobile/ is not folder, it's name of codeigniter controller that is also defined buy some other htaccess rules
I created subdomain mobile dot domain.com and i want to redirect all traffic from it WITH keeping URL in this form: mobile dot domain dot com/{path}
Try adding this to your htaccess:
RewriteCond %{HTTP_HOST} ^mobile.domain.com$ [NC]
RewriteRule ^(.*)$ /mobile/$1 [L]
If you have other rewrite rules in your htaccess file you may want to add this before the other rules.