Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.