473,659 Members | 2,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mod_rewrite/preg_match - yes/no, is there better way?

I would like to offer my registered users to have very short uri for
their pages in our comunity site, so I have enabled wildcard dns
*.bellay.com. and added virtaul host for it. (I'm testing this on one
domain I don't use so no harm will be done in testing time). and that is
working. than I tried to write mod_rewite rule in .htaccess which should
redirect anything.bellay .com to bellay.com/index.php?user= anything but I
failed.

rewriteEngine On
rewriteCond %{HTTP_HOST} !^$
rewriteCond %{HTTP_HOST} !^(www\.)?bella y\.com$ [NC]
rewriteCond %{HTTP_HOST}<->%{REQUEST_UR I} ^(www\.)?([^.]+).*<->/([^/]+)
[NC]
rewriteCond %2<->%3 !^(.*)<->\1$ [NC]
rewriteRule ^(.+) /%2/index\.php\?use r\=$1 [L]
so, I delitet those lines from .htaccess file and in my index.php, I put
on very top:

$server_host = explode('.', $_SERVER['HTTP_HOST']);
$subdomain = strtolower($ser ver_host[0]);
$not_users = "/\b(www|ftp|dev| mail|smtp|pop|s erver|localhost |root)\b/i";
if (preg_match($no t_users,$subdom ain)) {
echo" header(\"Locati on: http://bellay.com/\");";
}
else {
echo" header(\"Locati on:
http://bellay.com/?user=$subdomai n\");";
}

and that is working, but, before I implement that on my real site, I
have to ask if there is any bettar way to do that? are there any
drowbacks or potential (security) dangerous waitnig for me?

thank you very much.
Mar 19 '07 #1
0 1251

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
10232
by: mantrid | last post by:
Hello Found this piece of code using preg_match to check file types during upload of files. $allowed_file_types = "(jpg|jpeg|gif|bmp|png)"; preg_match("/\." . $allowed_file_types . "$/i", $_FILES) I understand the basic preg_match but am confused as to how the string pattern part is working i.e. "/\." . $allowed_file_types . "$/i"
11
3359
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
With Apache's mod_rewrite module I can keep *.php files and load them as *.html files: # Make http//example.com/foo/bar.html load /home/site/foo/bar.php RewriteEngine On RewriteRule ^(.*)\.html$ $1.php But, is there any elegant way to prevent direct access to "http//example.com/foo/bar.php"? No matter the "L" flag, all *.html requests get parsed again with any *.php rule I write, even though the
13
5364
by: chadsspameateremail | last post by:
I might have found a problem with how preg_match works though I'm not sure. Lets say you have a regular expression that you want to match a string of numbers. You might write the code like this: preg_match( '/^+$/', $TestString ); OK everything seems fine. However, did you know if you pass the following to preg_match: "12345\n" it will return that a match occurred?!? Even though the newline is not a valid character in our regular...
8
3991
by: Thomas Mlynarczyk | last post by:
Hello, I want to split a given string into tokens which are defined by regexes: // example tokens - a bit more complex in real $tokens = array( 'NUMBER' ='~^\d+~', 'NAME' ='~^+~', 'ANY' ='~^.~' ); // make sure there is always a match
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.