• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 887
  • Last Modified:

Catch-all URL

Hi all,

I am hosting a web page at PowWeb and what to have the following url

http://myweb.com/somekey

So, I need to catch 'somekey' and redirect to another url accordingly (possibly with a small php script).
Besides that, when I type http://myweb.com, I want to see the site's default page.

How can I achieve that? some specific htaccess directives?

Thanks in advance,
Jaime.
0
Jaime Olivares
Asked:
Jaime Olivares
  • 4
  • 3
2 Solutions
 
EMB01Commented:
You have to create an htaccess command that will route all requests to a certain page.  Once they are on that page, if your key does not find a match, you can do something, or if it does find a match, you can do something else.
0
 
Jaime OlivaresAuthor Commented:
EMB01,
I already know that, as expressed in my question. What I need are the specifics:
- What to put in the htaccess?
- What to put in the PHP script?
0
 
EMB01Commented:
It depends on your specific situation.  What is "somekey?"  You need to build a regex to match it.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jaime OlivaresAuthor Commented:
as said, I need a catch-all, so the regex must catch any string
If the string doesn't match my expectations, I will show an error message
0
 
EMB01Commented:
Try this:

RewriteCond  %{REQUEST_FILENAME} !-f 
RewriteRule ^/[\w\W]*$ processor.php?key=$1 [R,NC,L]

Open in new window

Then in process.php:
<?php

echo $_GET['key'];

?>

Open in new window

0
 
Jaime OlivaresAuthor Commented:
That sounds like an answer!
What if I have more than one domain in that server?
How do I constraint the catch-all rule to a specific domain?
0
 
EMB01Commented:
That I don't know.  You may want to open a new question.  I think you would have one .htaccess per domain, so you would just use the same code on different servers.
0
 
Mohamed AbowardaSoftware EngineerCommented:
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now