Using ISAPI rewrite - isapi-rewrite

I am using IIS and HELICON ISAPI rewrite. Previoulsy I had one website on IIS but have had to add another. So I have one default website and one virtual directory.
My home directory setup is C:\Inetpub\wwwroot\
within wwwroot I have two sub folders C:\Inetpub\wwwroot\site1 and C:\Inetpub\wwwroot\site2
I have something similar rewrite rules:
RewriteCond %{REQUEST_FILENAME} !(/site1.*) [NC]
RewriteCond %{REQUEST_FILENAME} !-s [NC]
RewriteRule (/site2/.*) /site2/urlhandler.cfm\?404;http\://%{SERVER_NAME}/$1\?%{QUERY_STRING}
This works ok however I get a file not found for all sub folders in site2. Anyone have any ideas?

Please try the following config instead:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !^/site1.* [NC]
RewriteRule ^(site2/.*)$ /site2/urlhandler.cfm\?404;http\://%{SERVER_NAME}/$1 [NC,L]

Related

.htaccess MAMP difference to environment

I'm building my site on MAMP, after a couple of days I finally got an .htaccess file to work after my will. But now when I upload to live environment it doesn't behave the same! Is there different versions? Is it because of error in my file that MAMP handles automatic?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 404.php [QSA,L]
Check if mod_rewrite is enabled in your live environment.

RewriteRule doesn't do anything

I am using the current set of re-write rules in my .htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule lessons/(.*)$ page.php?url=$1
It works fine. Now I have some old pages which I would like to redirect to new pages. I do the following:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule lessons/(.*)$ page.php?url=$1
RewriteRule old/this_url/(.*)$ lessons/to_this_url/and_this_url
But when I go to www.mywebsite.com/old/this_url/another_path it simply doesn't do anything?
I tested the rule in a re-write test program and it worked. The rule was recognised. So not sure, what I am doing wrong on the live website?
Answering my own question. In fact I realized a bit late that what I was trying to do was redirecting the content of an old website to a new website. They live under the same domain name but don't live under the same root. One lives under / (the current one) and the old one lives under /old/. So the rules needed to be added to the .htaccess of the old website. In:
www.root.com/old/.htaccess (THIS IS CORRECT)
While I was trying to edit them in:
www.root.com/.htaccess (NO)
That solves my problem.

What is the solution of making dynamic subdomain like links

I have a shopping mall site built with Magento. The url is like http://exampleshopping.com
Now I have requirement where each of my users will have a vanity URL like the following -
http://abc.exampleshopping.com
http://xyz.exampleshopping.com
In the above example abc, xyz are the user names.
How is this possible without creating a sub domain from the control panel. I need this to be created automatically when a user registers.
Create an .htaccess file with the following code to build a dynamic username as subdomain.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.exampleshopping\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.exampleshopping\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?username=%1 [L]
All visits to http://username.exampleshopping.com will redirect to www.exampleshopping.com/userpage.php?username=subdomain. User only see http://username.exampleshopping.com in the address bar.
Reference : http://www.panolee.com
Use the following code in your main .htaccess file (for the www subdomain) - or in the Apache Vhost config.
Replace sonassi.com and paths to suit.
RewriteEngine On
RewriteCond %{HTTP_HOST} !www\.sonassi\.com
RewriteCond %{HTTP_HOST} ([^\.]+)\.sonassi\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?user=%1$1 [L]
You need to also create a wildcard DNS A record, if you are using cPanel, you would use
*.sonassi.com => my.ip.add.ress
Or, if you are using TinyDNS - use the following syntax
+*.sonassi.com:my.ip.add.ress:86400
Using a htaccess regex url Rewrite will work for you.

Rewrite URLs for static content

I have problems with static files url rewriting in current .htaccess setup on apache2.
My app structure is:
/siteroot
/siteroot/app
/siteroot/lib
/siteroot/...
/siteroot/public <- all the static files (images, js, etc.) stored here
/siteroot/index.php
/siteroot/.htaccess
So, i need to rewrite url like /css/style.css to /public/css/style.css. I did that in really simple way, but when the file is not found it causing 10 internal redirects, which is bad. I need somehow to return 404 code if file not found, or just pass it to the next rule. And i dont have any access to site configuration file. Only .htaccess.
The reason why i`m asking this question is that the site was running on nginx and i need to rebuild the same configuration on apache.
Here is my .htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Test if a redirect is reasonable:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/public/$0 -f
RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]
If the number of prefixes is limited, you could add another group to your regex:
RewriteRule ^(css|js|images|etc)/.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [L]

xampp redirects

Does anyone has an example how to do a rule in .httpaccess in xampp?
I'm trying to redirect from localhost/test/company.php?name=Abc to localhost/test/company/Abc and I cant seem to find the solution. I followed some examples that I found on the web but none seems to work. I'm putting the .htacces file in the same folder where I have the company.php file. And I have the urlrewrite turned on.
Put the .htaccess file in your application root.
The .htaccess file should have something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^company/([a-zA-Z0-9\-]+)$ /company.php?name=$1 [L,NC]
Turn on mod_rewrite and restart apache.
Then it should work.

Resources