We are trying to migrate traffic from our old Netsuite store to a newer solution. The last step before launch is configuring the .htaccess file to redirect traffic from the old Netsuite URLs to the new SEF URLs.
Netsuite URL:
www.myoldstore.com/s.nl/sc.27/.f
New URL:
www.mynewstore.com/store-home-page
For launch, we will point the old domain "www.myoldstore.com" at our new server which is configured to accept traffic for this domain.
I configured the following .htaccess rules:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.myoldstore\.com [NC]
RewriteRule ^ https://www.mynewstore.com/store-home-page [L,R=301]
However, I just discovered that any traffic on our server (Apache 2) that has a path like the old Netsuite URL (/s.nl/sc.27/.f) generates a "Permission denied" message.
Is there some way to configure either the server or .htaccess to allow/handle paths like that?
UPDATE: I found the problem. The new site is a Drupal site, and Drupal's default .htaccess file includees the following rule:
RewriteRule "(^|/)\." - [F]
That is intended to block access to hidden directories. I didn't want to remove it altogether, so I moved it lower in the .htaccess file so it only processes after the specific old URLs have been handled.
The new site is a Drupal site, and Drupal's default .htaccess file includes the following rule:
RewriteRule "(^|/)\." - [F]
That is intended to block access to hidden directories. I didn't want to remove it altogether, so I moved it lower in the .htaccess file so it only processes after the specific old URLs have been handled.
Related
I have two version of my site. one is a mobile version and another one is desktop.
Path looks like this :
For Mobile : public_htm/mobile
For Desktop : public_html
I want to change the document root of my domain based on the device. I want to serve content from the mobile folder if the user's device is mobile & serve contents from public_html if user on desktop.
How can I do this with .htaccess?
I want to have my domain the same for both desktop and mobile, only document root changed by .htaccess based on the device.
You would need to add something like the following to the top of the root .htaccess file:
RewriteEngine On
# Prevent direct access to the "/mobile" subdirectory
# - redirect back to the root
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^mobile/(.*) /$1 [R=301,L]
# Rewrite all requests from mobile devices to the "/mobile" site
RewriteCond %{HTTP_USER_AGENT} ^iphone|android|etc$ [NC]
RewriteRule ^(?!mobile/).* mobile/$0 [L]
The mobile detection regex (RewriteCond directive) is just an example, the specifics are left up to the reader. (For reference: mobile browser user-agent strings)
The negative lookahead in the RewriteRule pattern prevents requests that have already been rewritten to the /mobile subdirectory from being repeatedly rewritten. If you have another .htaccess in the /mobile subdirectory containing mod-rewrite directives then this may be unnecessary.
The first rule redirects any direct traffic to the /mobile subdirectory back to the document root. However, if you have another .htaccess file in the /mobile subdirectory containing mod-rewrite directives then this redirect would need to be moved to that .htaccess file (it won't work here).
Just a note on terminology... This doesn't strictly change the "document root", as mentioned in the question. (Although it might "look like" it does from a client perspective.) This internally rewrites requests to a subdirectory (URL-rewriting). Server-side applications running in the /mobile subdirectory still see the document root as being the parent directory. You cannot change the "document root" in .htaccess, which can only be done by setting the DocumentRoot (or VirtualDocumentRoot) directive(s) in the server config.
I am trying to configure in apache httpd.conf for the below scenario. Can anyone please advise how to do it.
When the apache instance is up and some one tries to hit below url
http://mydomain.com/xxx
It should display content exists in sitemaintenance.html without changing url context path.
Assume sitemaintenance.html resides in /usr/local/apache/my-apache-instance/htdocs/sitemaintenance.html
Here xxx is a subdomain which is hosted separately from main domain (mydomain.com).
-KS
Try placing this into httpd.conf or .htaccess for your sub-domain:
RewriteEngine on
RewriteCond /usr/local/apache/my-apache-instance/htdocs/sitemaintenance.html -f
RewriteRule ^.*$ /sitemaintenance.html [PT,L]
The condition in RewriteCond enables rewrite only if that file exists, so you can dynamically add or delete it, without re-starting Apache or changing .htaccess.
We've had our site running on (say) stuff.com for a while, with a load of sub-domains for different applications, red.stuff.com, blue.stuff.com and of course a load of content stuff.com/things/in/my/head
We've recently purchased a new domain, awesome.com.
Can we configure Apache to replace the 'stuff.com' in any request that turns up, with 'awesome.com' permanently? Would this method keep any search engine listings and existing links valid?
Thanks
You can use Apache's rewrite engine. Add this to your virtual server configuration (either in http.conf or in the sites-enabled directory):
RewriteEngine On
RewriteCond %{HTTP_HOST} stuff.com
RewriteRule ^(.*) %{HTTP_HOST}$1 [C]
RewriteRule ^(.*)stuff.com(.*) http://$1awesome.com$2 [R,L]
The [C] chains the two rules together. The first rule inserts the requested domain name into the request. The next rule redirects the request to the new domain name, extracting the subdomain and the rest of the URL if necessary.
It should redirect any incoming request (I tested it with subdomains, files, and query strings in the URL), so the search engine links would still work. I don't know how it affects search engine ranking, though.
I have a hosting account which provides me a folder to publish my files for my domain (say www.example.com). I have set up Drupal for www.example.com with .htaccess at the top folder to enable clean-urls for the Drupal installation. Now I want to have a Wordpress installation under www.example.com/blog/ and have clean URLs for that blog. But while using .htaccess it is not working ok as the .htaccess at the top folder will override the sub-folder one. How to achieve what I intend to?
This really depends on the exact content of your respective .htaccess files.
One workaround is to add a RewriteCond to the head of the main .htaccess file that, if the request URI matches the sub-directory, stops parsing:
RewriteCond %{REQUEST_URI} ^/blog
RewriteRule .* - [L]
this should lead to the blog URLs being parsed properly, based on the rules specified there.
I have a web application that has one set of files used by 50+ clients and all the configuration for each site comes from a config.php file in their respective directories. This is accomplished with PHP parsing the URL. All this works fine, just having an issue with custom uploaded documents the client can do and are located in
/var/www/sites/user1/cache
There can be multiple subdirs. So when requesting
http://user1.site.com/cache/subdir1/image.jpg
it needs to be read from
/var/www/sites/user1/cache/subdir1/image.jpg
The client is allowed to upload any file type, so I just need the rewrite to take any /cache requests, then grab the subdomain and point to proper directory.
Came up with this, but am still getting an invalid page
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.site\.com$
RewriteRule ^cache/(.*)$ /sites/%1/cache/$1 [L]
Any help is appreciated.
If I read the RewriteRule documentation correctly, the L flag on its own would generate an internal redirection, meaning that the substitution would be interpreted as a local file system path.
Try using the complete path:
RewriteRule ^cache/(.*)$ /var/www/sites/%1/cache/$1 [L]
or do an external redirection (using HTTP return status "302 MOVED TEMPORARILY"), to let the user's browser re-send the request with the new path:
RewriteRule ^cache/(.*)$ /sites/%1/cache/$1 [L,R]
The /var/www/ is where the files are on the filesystem. I was routing based on the document root so I didn't need to put that there. But I realized I was missing the leading forward slash on the /cache/. Though your answer wasn't really what I was looking for, it made me see what I was missing. Thanks.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.site\.com$
RewriteRule ^/cache/(.*)$ /sites/%1/cache/$1 [L]