1

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
}
?>
vfn
  • 6,026
  • 2
  • 34
  • 45
Kiloku
  • 553
  • 3
  • 8
  • 18
  • http://stackoverflow.com/questions/6768793/get-the-full-url-in-php – Fabricator Jul 24 '14 at 23:29
  • 3
    can't you just keep your solution, and just rewrite the incoming request for `www.exmple.org/~(....)` to `/?prof=$1` internally using a mod_rewrite rule in your `.htaccess` file? This doesn't even require a PHP solution. – Mike 'Pomax' Kamermans Jul 24 '14 at 23:30

2 Answers2

2

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

RewriteEngine On
RewriteRule ^\~([^/]*)$ /?prof=$1 [L]
dave
  • 62,300
  • 5
  • 72
  • 93
  • I can't check right now, but I assume this works. Gonna try tomorrow when I'm at work again. Thanks, @dave . I'm pretty new to web development, so I'm sorry if that's a very basic thing. – Kiloku Jul 25 '14 at 01:19
  • Kiloku mentioned they are using wordpress so I don't think this would work without nuking the existing WP rewrite rules. It also looks like they're using pretty links so this is already happening! Unfortunately I don't have the time to answer, but I think the solution rests in adding a rewrite rule: `add_rewrite_rule('^~([^/]*)$','index.php?prof=$matches[1]','top');` – The Maniac Jul 25 '14 at 02:08
  • @TheManiac - there is no reason you couldn't use that rewrite rule with wordpress – dave Jul 25 '14 at 02:52
0

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.

Community
  • 1
  • 1
Sid
  • 1,144
  • 10
  • 21