I'll be signing businesses up to advertise on my website, and I want them to have a direct URL for their customers to go to.

Like, instead of www.website.com/page.php?id=324234234,

I want to have www.website.com/businessname

Is there a simple way to do this? I've searched and seen a whole bunch of different things people are trying to do but I haven't seen anything that's the same as what I want to do.

I'm using a VPS, and I want to make sure that I don't open up permissions so that anyone can get in there and mess things up.

Also, these users will not be signing themselves up. I will be doing that.

The simplest way to get my end result is what I'm looking for. Thanks!

有帮助吗?

解决方案 2

Re-iterating what jtheman said with a little more explanation:

Create a file named .htaccess with the contents:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ page.php?businessname=$1 [L]

You need, of course, the ability to have directory level .htaccess enabled - you're using a VPS so you should be able to do this if it is not already enabled.

So let me explain what each line will do.

RewriteEngine on

Turns on the ability to URL re-write

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Tells Apache not to re-direct files that exist in the directory already

RewriteRule ^(.*)$ page.php?businessname=$1 [L]

This is where the magic happens.

^(.*)$ this part is like a regular expression match. It will tell Apache to collect any URLs that have any characters within them and redirect them to page.php?businessname=(.*)

So, if you post: www.website.com/stackover

It will really be sending: www.website.com/page.php?businessname=stackover

Then you can just use $_GET[businessname] to dynamically update the page.

Hope this helps!

其他提示

Basic URL rewriting could work.

Add to your .htaccess file

 RewriteEngine on
 RewriteRule ^(.*)$ page.php?businessname=$1 [L]

Then use PHP to rewrite the businessname to the ID of the company / find the data.

Of course .htaccess rewrite rules is a complete science if you need more complex rewriting...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top