Archive for the ‘htaccess’ Category
Wildcard DNS – subdomain profile
A wildcard DNS record is a record in a DNS zone that will match requests for non-existent domain names. A wildcard DNS record is specified by “*” as the left most label of a domain name, e.g. *.example.com.
DNS zone Entry
| example.com. 86400 | IN | SOA | example.com. hostmaster.example.com. |
| IN | NS | ns1.example.com. | |
| IN | NS | ns2.example.com. | |
| IN | MX | 10 mail.example.com. | |
| IN | A | 192.168.1.1 | |
| A | 192.168.1.1 | ||
| ns1 | A | 192.168.1.1 | |
| ns2 | A | 10.0.0.2 | |
| *.example.com. | A | 192.168.1.1 |
.htaccess file:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com
RewriteRule ^$ profile.php?uid=%1
</IfModule>
Now if you want sandeepverma.example.com it will redirect to profile.php with uid=sandeepverma
Find Apache Document Root
solution: Find Apache Document Root
# grep -i 'DocumentRoot' httpd.conf
# find / -name httpd.conf
or
# locate httpd.conf
(if file here /etc/httpd/conf/httpd.conf)
# grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf
Protect file uploads via PHP
Check server-side MIME type of uploaded files
The PHP form variable $_FILES['file']['type'] does not return correct mime type, so we have to use some php functions like…….
> finfo_file()
> getimagesize()
> exif_imagetype()
if(version_compare(substr(PHP_VERSION,0,1),5) == -1)
{
$san = finfo_open(FILEINFO_MIME);
$mime = finfo_file($san,$FileName);
$tmpvar = explode(";", $mime);
finfo_close($san);
if($mime == "image/jpeg")
{
echo "this is jpeg";
}
else
{
echo "this is not jpeg";
}
}
One can use getID3 [http://getid3.sourceforge.net/] classes to get mime type other than images….
Don’t upload to a web accessible directory
Protect your directory to execute perticular file type by putting a .htacces file in directory
AddType text/plain .php .js .cgi
more help here:
http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html
domain htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.mydomain\.com
RewriteRule ^(.*)$ index.php?blogger=%1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.sub.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.(.*)
RewriteRule ^(.*)$ http://www.domain.com/sub/$1 [R=301,L]
RewriteEngine on
# If no-www domain requested, externally redirect to www domain
rewritecond %{http_host} ^mysite\.net
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]
# If www+subdomain domain requested, externally redirect to subdomain without “www”
rewritecond %{http_host} ^www\.([^.]+)\.mysite\.net
RewriteRule (.*) http://%1.mysite.net/$1 [R=301,L]
# If subdomain+www domain requested, externally redirect to subdomain without “www”
rewritecond %{http_host} ^([^.]+)\.www\.mysite\.net
RewriteRule (.*) http://%1.mysite.net/$1 [R=301,L]
# If www domain requested, rewrite html page requests to profile.php with query string
rewritecond %{REQUEST_URI}!^/profile\.php
rewritecond %{http_host} ^www\.mysite.net
RewriteRule ^([^.]+)\.html /profile.php?page=$1 [L]
# If subdomain requested, rewrite subdomain and html page requests to profile.php with query string
rewritecond %{REQUEST_URI}!^/profile\.php
rewritecond %{http_host}!^www\.mysite\.net
rewritecond %{http_host} ^([^.]+)\.mysite\.net
RewriteRule ^([^.]+)\.html /profile.php?user=%1&page=$1 [L]
# If www domain requested, rewrite home page requests to profile.php with query string page = “home”
rewritecond %{REQUEST_URI}!^/profile\.php
rewritecond %{http_host} ^www\.mysite.net
RewriteRule ^$ /profile.php?page=home [L]
# If subdomain requested, rewrite home page requests to profile.php with query string user=subdomain & page=”home”
rewritecond %{REQUEST_URI}!^/profile\.php
rewritecond %{http_host}!^www\.mysite\.net
rewritecond %{http_host} ^([^.]+)\.mysite\.net
RewriteRule ^$ /profile.php?user=%1&page=home [L]
# If non-www domain requested, externally redirect to www domain
rewritecond %{http_host} ^mysite\.net
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]
# If www+subdomain or subdomain+www domain requested, externally redirect to subdomain without “www”
rewritecond %{http_host} ^www\.([^.]+)\.mysite\.net [OR]
rewritecond %{http_host} ^([^.]+)\.www\.mysite\.net
RewriteRule (.*) http://%1.mysite.net/$1 [R=301,L]
# if home page requested, rewrite to ‘home.html’ and pass through to following rules
RewriteRule ^$ /home.html
# If www domain requested, rewrite html page requests to profile.php with query string
rewritecond %{http_host} ^www\.mysite.net
RewriteRule ^([^.]+)\.html$ /profile.php?page=$1 [L]
# If subdomain requested, rewrite subdomain and html page requests to profile.php with query string
rewritecond %{http_host} !^www\.mysite\.net
rewritecond %{http_host} ^([^.]+)\.mysite\.net
RewriteRule ^([^.]+)\.html$ /profile.php?user=%1&page=$1 [L]
Leave a Comment
Leave a Comment
Leave a Comment