0

I'm working on a website on my local machine using PHP.
In my .htaccess file, I have the following line:

RewriteRule ^project-details/([a-zA-Z0-9-]+)/ project-details.php?pn=$1 [NC,L]

On the products page, I have the items containing a link like ./product-details/icecap-mouse249/...which the .htaccess file would in turn take and assign "icecap-mouse249" to the "pn" found at the end of the line: ?pn=$1 [NC,L].

When one clicks on the item, the person is then taken to the product details page. In that page, I have the following line:

$pn = $_GET['pn'];

This allows the URI to pull the 'pn' value and assign it to the variable $pn and utilize the variable to pull data from a database and display all the information of that particular product.

So, it works locally on my machine, but when I upload the files the page doesn't pull anything with $_GET[pn].

The product details page works because when I hardcode the value to $pn as in:

$pn = 'icecap-mouse249';

the page displays properly...pulling the data from the db.

I've done a phpinfo(); to see if the mod_rewrite is enabled, but the "Loaded Modules" section of the phpinfo page doesn't display. I did a CTRL+F to see if I could find the 'mod_rewrite' through the FIND tool, but nothing pops up.

The thing that trips me up is that it works locally on my machine.

I spent an hour with my host provider...and they weren't any help.

I hope I explained myself right and any insight would be greatly appreciated. Thank you.

1 Answer 1

0

You code is correct

Looks like you are dealing with special server configurations. Try disabling multiview (add to .htaccess) which might been causing issues in 1and1, and also try separetly adding AllowOverride all.

Options -MultiViews
AllowOverride All

After uploading the file, when you click on your link, does the page displays any errors? Does it display anything at all?

You said, you have your links pointing to ./product-details/icecap-mouse249/. Make sure the page where you are putting your links is in the root diretory like:

http://example.com/page-with-links.php

But if the page with the links is outside the root directory it will not work.

http://example.com/xyz/page-with-links.php

This is because you are asking to look for ^project-details which means

http://localhost/project-details/any-string/ or http://example.com/project-details/any-string/

5
  • Thanks for looking over my code. All my files are in the root directory, along with the .htaccess file. The odd thing is that the webpages work on my local server I have on my laptop (XAMPP), it works on GoDaddy server (when I had it there, but I've since transferred over to 1and1)...and that's where it's not working...on the 1and1 server. I've spoken to customer service, but they couldn't do much more than just confirm whether or not the mod_rewrite was enabled on the apache configuration; which they said they were. So, I'm baffled now.
    – Lexiriam
    Commented Mar 5, 2017 at 22:16
  • I edited the answer. Try adding to the .htacces "Options -MultiViews and AllowOverride All".
    – docliving
    Commented Mar 6, 2017 at 17:25
  • I tried adding what you recommended and still didn't work. I'll need to keep troubleshooting. I've done some research on StackOverflow with the same issue; sadly nothing worked for me. Thank you, either way.
    – Lexiriam
    Commented Mar 9, 2017 at 21:03
  • I for some reason you need to stick with 1&1, you'll finish your project faster if you write a php script that handles the redirection, rather than doing it with .htaccess - It is definitely a 1&1 issue. After doing some searching more people had the same problem with 1&1, and it was never clear how they solved the situation
    – docliving
    Commented Mar 10, 2017 at 16:12
  • That's what I've resigned myself to accept, unfortunately. Thanks for your recommendations and responses @docliving.
    – Lexiriam
    Commented Mar 10, 2017 at 16:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.