developerdave Posted April 15, 2010 Share Posted April 15, 2010 Hey guys, Working on a site, and Regex isn't my strongest point I'll admit. So what I'm looking at doing is rewriting a url such as www.example.com/web-design.php so that it actually calls index.php (I'm working with file name variables for my queries) I have no idea where to start with this could anyone give me an idea? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/198639-complicated-regex/ Share on other sites More sharing options...
JAY6390 Posted April 15, 2010 Share Posted April 15, 2010 A .htaccess file with something like RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] should work Quote Link to comment https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042391 Share on other sites More sharing options...
developerdave Posted April 15, 2010 Author Share Posted April 15, 2010 It works in the sense its requesting index.php but my aim is to use web-design.php as bit of a get variable if you see what I mean. So /web-design.php calls index.php and inside index.php I have a query that uses $_SERVER['SCRIPT_NAME'] that I use in my query. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042396 Share on other sites More sharing options...
JAY6390 Posted April 15, 2010 Share Posted April 15, 2010 Something like this maybe? RewriteEngine On RewriteBase / RewriteRule ^([\w-]+)\.php$ index.php?q=$1 [L] then in index.php use $_GET['q'] for the query You could of course just use the code I gave in the first example along with $_SERVER['REQUEST_URI'] to get the uri, then regex that for the query Quote Link to comment https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042403 Share on other sites More sharing options...
developerdave Posted April 15, 2010 Author Share Posted April 15, 2010 Hey, thanks Jay I went for the $_SERVER['REQUEST_URI'] method and it worked perfectly Cheers man Quote Link to comment https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042409 Share on other sites More sharing options...
JAY6390 Posted April 15, 2010 Share Posted April 15, 2010 Cool, no problem Quote Link to comment https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042411 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.