Throttlehead
Throttlehead

Reputation: 1945

htaccess redirect question

Ok, so my htaccess file first rewrites any url to include the full address. I needed this because facebook is picky about the urls coming through for the application ID.

Now, this site I'm building is a business profile site of sorts, built with PHP and MYSQL. The profile page can query based on either the id number, or the unique slug id, which acts as an easy-to-read URL for the businesses to use when they want people to link to their profile. So I have the rewrite engine putting the string into a variable in the URL so the profile page can get the string and use it to query. As of right now, it's going to rewrite any URL or file that doesn't exist and send it to the profile page. This seems a little sloppy, as I wouldn't want a user who enters an incorrect URL for, say, the contact page, and instead get's sent to the invalid profile page. Here's the rule:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* profile.php?uniqueID=$0 [L] 

Now, I'm thinking the only real way I could do this instead is to make the urls more unique, so instead of www.bizprofiles.com/uniqueprofilename as the basic structure, I do www.bizprofiles.com/profils/uniqueprofilename and instead write the condition to exact match the url up until the unique name.

I'm wondering if anyone has any better of an idea?

Upvotes: 0

Views: 132

Answers (1)

konsolenfreddy
konsolenfreddy

Reputation: 9671

.htaccess can't check you business logic, e.g. if a profile exists. You will have to check within profile.php and redirect appropriately like:

header('HTTP/1.0 404 Not Found');
header('Location: /your404File.php');
exit;

The second structure www.bizprofiles.com/profils/uniqueprofilename (I think there's a spelling mistake, should be profiles or profile) would be more readable in my opinion and gives you the opportunity to extend the site with different .htaccess rules at some point.

Upvotes: 1

Related Questions