Kiloku
Kiloku

Reputation: 553

Is it possible to make PHP interpret a symbol as a $_GET in the URL?

Sorry for the strange phrasing.

I'm working on a project to upgrade an University's website (this is not a school project, they hired the company I work for to do it).

We're working with wordpress, and the pages for professors are not single pages to be displayed directly, instead, they're shown in a modal on top of the main page.

To do that, I used $_GET, so when the user enters www.example.com/?prof=isaac-newton on their browser, they see the page at www.example.com with a modal on top of it,

this modal has the content of www.example.com/professors/isaac-newton in it.

The clients didn't like this very much, because their current system works with the user entering www.example.com/~isaac-newton, and they want to keep this standard.

Finally, my question is:

Can I make PHP interpret something such as ~isaac-newton in the url as ?prof=isaac-newton? How?

Here is my current code which makes ?prof= work:

<?php

if (isset($_GET['prof']))
{
    $prof = $_GET['prof'];
?>
    <script type="text/javascript">
        $('#modal').modal({'remote' : 'http://www.example.com/professor/<?php echo $prof; ?>/'});
    </script>
<?php
}
?>

Upvotes: 1

Views: 64

Answers (2)

dave
dave

Reputation: 64657

If you are on apache for the webserver, you can add this to your .htaccess file:

RewriteEngine On
RewriteRule ^\~([^/]*)$ /?prof=$1 [L]

Upvotes: 2

Sid
Sid

Reputation: 1144

You could look into using URL rewriting technology to solve your problem. I don't know what kind of web server you're using but if it's Apache then take a look at the Apache mod_rewrite module. Also, have a look at this question: URL rewriting with PHP. This should put you on the right track.

Upvotes: 0

Related Questions