Jump to content

Complicated Regex?


developerdave

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/198639-complicated-regex/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042396
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/198639-complicated-regex/#findComment-1042403
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.