.htaccess in subdomain - apache

I'm trying to set up a subdomain as follows:
http://subdomain.domain.com should load what is really http://subdomain.domain.com/index.php/contest/
http://subdomain.domain.com/stepone should load what is really http://subdomain.domain.com/index.php/contest/stepone
http://subdomain.domain.com/images/example.jpg should load http://subdomain.domain.com/images/example.jpg as normal.
I've had this all set up and working in a subdirectory on the main domain before but now that I'm trying to do it on a subdomain it's stopped working.
Here is my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|javascript|email|robots\.txt|test\.php|terms\.html)
RewriteRule ^(.*)$ /index\.php/contest/$1 [L]
Please help me!

Are rewrite rules working at all? I.e. do you have AllowOverride All or something for virtual hosts, as per:
http://www.webhostingtalk.com/showthread.php?t=481815
Also, take a look this comment by Gumbo on this SO question:
Htaccess help, $1 being used before its set??? what?

The Drupal .htaccess file is a good example of mapping /?q=query to /query, but not redirecting things which provide an explicit file/directory match. Here's the relevant snippet from Drupal's .htaccess with ?q= changed to index.php/contest/.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/contest/$1 [L,QSA]
If you need to restrict the domain so that it doesn't redirect normally but just from the one domain, insert before the RewriteRule this:
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]

I think I have found the answer using:
RewriteRule ^(.*)$ subdomain.domain.com/index\.php/contest/$1 [L, P]
Is there any reason I shouldn't use the force proxy like this? (Does it slow things down?)
Thanks for your answers guys.

Related

Wildcard redirect with .htaccess

I would like to redirect this pattern with .htaccess:
https://www.example.com/abcdef1/products
https://www.example.com/abcdef2/products
https://www.example.com/abcdef3/products
to
https://www.example.com/abcdef1/
https://www.example.com/abcdef2/
https://www.example.com/abcdef3/
How can I achieve that?
Could you please try following, written as per shown samples. After placing these Rules into your .htaccess file, make sure you clear cache of your browser before testing it.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/abcdef[0-9]+/?$ [NC]
RewriteRule ^(.*)$ $1/products [L]

RewriteRule doesn't rewrite correctly

I'm hosting my development site on the localhost server and I used to access it at 127.0.0.1/dev. In the folder I have a .htaccess file containing following information. I'm new with the RewriteEngine and don't get this work.
RewriteEngine on
RewriteRule ^/(.*)$ /index.php?page=$1
When I'm trying to access 127.0.0.1/dev/home, I simply get a message that the page doesn't found. I can't see where rewrite is redirecting me, so I can't debug the problem in easy way. I think that you can see the problem at the first look.
Thanks in advance.
Try this rule in /dev/.htaccess without leading slash in source pattern and target URL:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$0 [L,QSA]

How to implement ssl on everything except a specific and/or a few specific files/folders using .htaccess

I am implementing SSL on everything but would like to exclude a specific page or specific set of pages from using SSL. How can I do this. At the moment I am using the simple syntax:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain/myfolder/$1 [R,L]
If you could could you explain the steps you are taking in order to do this please so that I can actually understand why and what you have done and I will learn something from this?
Thanks for the help,
John
You can use it like this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/(excluded1|excluded2)/ [NC]
RewriteRule ^(.*)$ https://mydomain/myfolder/$1 [R,L]
RewriteCond %{REQUEST_URI} ! is for excluding listed paths in https redirection.

How to create mode_rewrite rule on Apache Server FreeBSD 8.1

I'm Working on a server running apache version 2.2.25 on FreeBSD 8.1.
Lets say I have the the following url: this.domain.com/html/folder/index.php
And I want to rewrite it as this: this.domain.com/index
How specifically would I create the rewrite rule? Should I create the rewrite rule in the httpd.conf file or the .htaccess file, or does it not really matter?
Also, is there a way to change the domain name "this.domain.com" to something else?
Assuming, you want users to enter the shorter url this.domain.com/index and serve the php at this.domain.com/html/folder/index.php; add the following rules to the .htaccess at root /.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^this\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ html/folder/$1.php [L]
I'm not sure what you mean by changing your domain to something else. this.domain.com can be changed to that.domain.com or addon-domain.com but would make sense only if their DNS point to the same server (to serve shared content). Otherwise, it's like an external redirect to some other site.
RewriteCond %{HTTP_HOST} ^this\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://that.domain.com/$1 [R=301,L]
Try this
RewriteRule ^/index$ /html/folder/index.php [PT]

Apache htaccess URL rewrite

I have a URL like -
http://www.mydomain.com/website/dev/main/html/about_us.html
How can I rewrite it to simply http://www.mydomain.com/about ?
I have seen many examples of URL rewrite on internet and SO but still couldn't figure it out. Any help would be appreciated.
Try this in your htaccess, make sure that mod_rewrite is actuvated on your server:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^about$ ./website/dev/main/html/about_us.html
Working from the Apache Rewrite Guide, your .htaccess file should contain:
RewriteEngine on
RewriteRule ^/about$ ./website/dev/main/html/about_us.html [R]
That turns the rewrite engine on (if it isn't already) and then sets up a rule. Any URL after the domain that matches the regex ^/about$ will be redirected transparently to /website/dev/main/html/about_us.html
I'm sure this is a repeat of an existing question. Make sure you have in your file:
RewriteEngine On
RewriteBase /
RewriteRule ^about$ website/dev/main/html/about_us.html
You can also pass vars this way too:
RewriteRule ^about/(.+)/(.+)$ about/index.php?q=$1&p=$2
Where about/12/23 would equal about/index.php?q=12&p=23