I want to redirect styles requests from subdomain to main domain
https://dir.example.com/assets/(.*) to https://example.com/assets/(.*)
I am able to successful manage this issue with subfolder via bellow code:
example.com/dir/assets/(.*) to example.com/assets/(.*)
RedirectMatch 301 ^/dir/assets/(.*)$ /assets/$1
I tried to modify for subdomain but bellow code is not working:
RedirectMatch 301 ^dir.example.com/assets/(.*)$ example.com/assets/$1
what will be correct way of rewriting assets from sub-domain to main domain ?
I did it:
RewriteCond %{HTTP_HOST} ^(.*)\.example\.org[NC]
RewriteRule ^/?assets/(.*)$ https://example.org/crm/assets/$1 [L,R]
but now i have bigger issue:
Access to font at 'https://example.org/crm/assets/plugins/roboto/fonts/Regular/Roboto-Regular.ttf?v=1.1.0' from origin 'https://crm1.example.org' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Edit
Found Solution for second issue
.htaccess
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
Related
How to redirect all useragent except useragent wget ? what to add?
SetEnvIf User-Agent .*Wget* wget
Order deny,allow
Deny from all
Allow from env=wget
You could just add a "redirecting" ErrorDocument directive to your existing directives. For example:
ErrorDocument 403 https://example.com/url/to/redirect/to
When combined with your existing directives (that "block" all other User-Agents) this will trigger a 302 (temporary) redirect to the stated URL for anything other than wget.
Alternatively, replace your existing directives with the following mod_rewrite rule instead:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !Wget
RewriteRule ^ https://example.com/url/to/redirect/to [R=302,L]
Both of these assume the URL you are redirecting to maps to a different server, otherwise, you'll like get a redirect loop.
i have site there both url are working as follow
https://domainname/abc
https://domainname//abc
so i just want to redirect //abc to 404 error page for preventing duplicate content i try following rule but didn't work.
RewriteRule ^//(.*)$ 404
ErrorDocument 404 https://domain_name/404
i also try using RedirectMatch as follow
<IfModule mod_alias.c>
RedirectMatch 404 ^//(.*)$ https://domain_name/$1
</IfModule>
Hi I've got a wierd issue after a htaccess url rewrite... it works fine for the homepage but if i use the format subdomain.domain.com some fonts don't work, some do. The icons don't work it just shows a placeholder icon. It can't load the woff files etc. I think it may be the htaccess directoryindex disabled but i've put a special rule to allow the homepage to be displayed. How do I do the same for the \img\font\ folder which has the fonts. Also more importantly is disabling directoryindex best practice (i did this to avoid index.html being appended to the url's otherwise the rewrite subdomains doesn't work as it always encounters trailing index.html. Is there a way to set directoryindex to empty "" so that the second query works and I don't have to keep adding rules to allow specific folders?
DirectoryIndex disabled
#rewrite homepage to index.php to allow homepage as directoryindex is disabled
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/?$ index.php [L]
#Rewrite subdomains
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ^(^.*)\.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/index.php?sub=%1 [P,NC,QSA,L]
Thanks!
P.S The earth really is flat.
I'm getting CORS errors in the console but it's the files are on the same server and domain.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/img/icon/fonts/materialdesignicons-webfont.woff2?v=2.0.46. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)
downloadable font: download failed (font-family: "Material Design Icons" style:normal weight:normal stretch:normal src index:1): bad URI or cross-site access not allowed source: http://example.com/img/icon/fonts/materialdesignicons-webfont.woff2?v=2.0.46
Adding this to htaccess fixed everything
<IfModule mod_headers.c>
#allow corrs access from subdomains
SetEnvIf Origin ^(https?://(?:.+\.)?example\.com(?::\d{1,5})?)$ CORS_ALLOW_ORIGIN=$1
Header append Access-Control-Allow-Origin %{CORS_ALLOW_ORIGIN}e env=CORS_ALLOW_ORIGIN
Header merge Vary "Origin"
</IfModule>
We've moved a site to another domain and setup the htacess as bellow, but how can i set a rule "if page dosnt exist - (ie 404 error) redirect to new site homepage." To be used as a fall back, if someone follows a broke url to our old site.
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.oldsite\.co\.uk)(:80)? [NC]
RewriteRule ^(.*) http://oldsite.co.uk/$1 [R=301,L]
Redirect permanent http://oldsite.co.uk http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/index.html http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/contact-us.html http://newsite.co.uk/contact-us.html
Redirect permanent http://oldsite.co.uk/bespoke-furniture.html http://http://newsite.co.uk/bespoke-furniture.html
Redirect permanent http://oldsite.co.uk/about-us.html http://newsite.co.uk/about-us.html
Redirect permanent http://oldsite.co.uk/how.html http://newsite.co.uk/about-us.html
order deny,allow
You could simply use this.
ErrorDocument 404 http://newsite.co.uk
I just migrate my site from asp to opencart. In .htaccess I would like to do some redirect so that my customer can use back the old link to access
inside .htaccess
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads
For Contact Us that work perfectly, however, for the downloads url, it didn't work correct.
when I access to http://www.example.com/downloads.asp it will redirect to http://www.example.com/downloads?_route_=downloads.asp
and Opencart show it is page not found.
For the http://www.example.com/downloads we had set SEO friendly URL in the backend system.
We able to access with
http://www.example.com/information/downloads
http://www.example.com/downloads
but we not able to access with normal link
http://www.example.com/index.php?route=information/downloads
The folowing is my full .htaccess
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads
============ANOTHER TESTING========================
I did some testing on this on my localhost I found out it is a quit interesting result. However, my problem still haven't solve.
I run the .htaccess from http://localhost/example and http://example (added virtual directory)
For http://localhost/example
redirect 301 /example/downloads.asp http://localhost/example/downloads/
and
For http://example
redirect 301 /downloads.asp http://example/downloads/
Then I tried, redirect to my live version link, from localhost (http://example)
redirect 301 /downloads.asp http://www.example.com/downloads/
I access to http://example/downloads.asp
The browser redirect to me
http://www.example.com/downloads?route=downloads.asp
NOTED
In LIVE version, I did not added any redirect code [VERY SURE FOR THIS]
But in Live version, I am to access directly with enter
http://www.example.com/downloads
I am not sure why from localhost redirect 301 to live version will come out
http://www.example.com/downloads?route=downloads.asp
Any idea?
Solution Found:
.htaccess redirect 301 working with opencart v1.5.4.1
Additional code needed for... (and credits of this fix):
https://github.com/opencart/opencart/pull/142
... replace contents of:
- catalog/controller/common/seo_url.php
- system/library/url.php
Redirect Fine:
RewriteRule contacto http:....com/index.php?route=information/contact [R=301,L]
Redirect Not Working:
redirect 301 contacto http:....com/index.php?route=information/contact
Verified.
Put it in front of router. Also add $ after .asp and ^ in front.
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us
redirect 301 ^downloads.asp$ http://www.example.com/downloads
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Why don't you redirect contact to /information/contact_us instead of index.php?route=information/contact_us ?
You can try a "?" at the end of the redirect url if it is not present there like 2nd url(it worked for me) :
redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us
redirect 301 /downloads.asp http://www.example.com/downloads?