Help with .htaccess needed

Status
Not open for further replies.

nogenius

likes money
Mar 16, 2007
487
3
0
Texas
Working with database sites, my issue right now is that say my database-driven site URL is www.mysite.com, my .htaccess is currently set up that it returns a 200 (Successful) header on any request (e.g. complete gibberish like www.mysite.com/sdjgdsfklr). I've heard this is bad for SEO.

I'm trying to rewrite my .htaccess so that only requests in certain formats get redirected to index.php.

My URL's are formatted like: data1-data2-data3.html and data1-data2-data3-data4.html. URLs formatted anyway else should not exist. Therefore, I tried using the following lines of code to send correctly formatted URLs to index.php to generate a page, and everything else to return a 404.

Code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-(.*)-(.*).html$ index.php?q=$1
The code didn't have the fully desired effect, it only passes the first (.*). I'd like it to pass the entire string between the anchors ^ and $ (the (.*)-(.*)-(.*)).

If anyone could offer some guidance on what I could do to have the .htaccess pass the entire string as the backreference $1, that would be greatly appreciated.
 


I'm no expert, but I think you need to do:


Code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-(.*)-(.*).html$ index.php?q=$1-$2-$3
RewriteRule ^(.*)-(.*)-(.*)-(.*).html$ index.php?q=$1-$2-$3-$4

or possibly simpler:

Code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*).html$ index.php?q=$1

I assume you'll be using php to explode the arguments into an array.
 
Send everything to the script and have t check for validity (is that a word) and if it doesn't validate, send a 404 header and page using the script.
 
Send everything to the script and have t check for validity (is that a word) and if it doesn't validate, send a 404 header and page using the script.

Yea.. I agree with nis. A script will give you more flexibility and it's usually easier. Just don't redirect images, etc to the script. Your server load will be
relatively small if your site is small.

All the best
 
Thanks everyone for their responses so far, that was helpful.

Just for clarification, when you say script, do you mean PHP script?
 
A PHP script will do, but really any language you are comfortable in.
 
Status
Not open for further replies.