0

Hi!
I'm currently developing a website and I'd like to rewrite the URLs with htaccess. I've looked up some tutorials on how to do it, but it doesn't seem to work. This is one of the url's :

products.php?sub=997&id=97084&name=Manual-Control

I'd like the link to become:

products/997/97084/Manual-Control

This is my current .htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/(.*)/(.*) products.php?sub=$1&id=$2&name=$3

The problem is that the URL doesn't get rewritten. I uploaded the .htaccess file in the public-html folder (where products.php is)

Any help on this? Thanks in advance!

2
Contributors
12
Replies
14
Views
5 Years
Discussion Span
Last Post by pritaeas
Featured Replies
0

.* is greedy, so it will take too much, most likely. You can try:

RewriteRule ^(\d+)/(\d+)/(.*)$ products.php?sub=$1&id=$2&name=$3 [L]

Assuming the first two will only contain digits. If that also does not work, try the simplest first, something like this:

RewriteRule ^test$ products.php [L]

It should rewrite http://examples.com/test to http://example.com/product.php. If that does not work either, contact your host to see if mod_rewrite is enabled.

0
RewriteRule ^(\d+)/(\d+)/(.*)$ products.php?sub=$1&id=$2&name=$3 [L]

Doesn't work, and

RewriteRule ^test$ products.php [L]

does, because entering /test brings me to /products.php, so I assume mod_rewrite is enabled..

What am I doing wrong?

EDIT: The first and second rules CAN contain both letters and numbers from time to time

Edited by Synestic

0

How about with a single first:

RewriteRule ^(\w+)$ products.php?sub=$1 [L]

Then try with two:

RewriteRule ^(\w+)\/(\w+)$ products.php?sub=$1&id=$2 [L]
0

That didn't work either.
What I did just notice is that when I add

RewriteRule ^test$ products.php [L]

The page that'll be displayed is products.php but the URL will still say "www.blabla.com/test" and not "www.blabla.com/products.php"

0

hmm OK I guess that was pretty stupid of me :D
Is there anything else I can try? :/

0

OK, the htaccess I'm now using seems to return everything from my db :

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^products/([^/]*)/([^/]*)/([^/]*)$ /products.php?sub=$1&id=$2&name=$3 [L]

so /products/P97/p97084/PSE-Manual-Control retrieves everything from the database through mysql, but the problem now is that my CSS file and images aren't loading. I guess this is because the browser thinks it should get the CSS file from the folder /products/ ..
Any help with this?

EDIT: It thinks the folder is /products/p97/ now..

Edited by Synestic

0

Make sure you use absolute links.

Are absolute links a standard in web development or is there just no way to get around them?

0

Since your file now appears to be in a folder, you need a way to open it. Absolute path is sure to work. I don't make claims about standards, but I prefer absolute links.

0

Since your file now appears to be in a folder, you need a way to open it. Absolute path is sure to work. I don't make claims about standards, but I prefer absolute links.

OK, I changed every link to an absolute one and got everything working. Weird thing is, my php include couldn't open the absolute link so I had to keep the relative link.

Thanks for helping me!

0

Yes, true. For HTML/CSS starting with a backslash means the www root, and for PHP it means the root of the current volume.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.