robholmes83
asked on
RewriteRule in htaccess problem
Hi everyone, I really hope someone can help me?
I'm trying to get my urls to look like this:
http://www.mydomain.com/products/subproduct/detail
...when the actual file is an html file to be 'include'd in a index.php for example:
http://www.mydomain.com/products/index.php?p=subproduct/detail
...my index.php file would look something like this:
<html>
... blah blah ...
<?php
clearstatcache();
if (file_exists($HTTP_GET_VAR S[p].".htm ")) {
$page = $HTTP_GET_VARS[p];
echo "The file filename exists";
} else {
$page = 'products';
echo "The file filename does not exist";
}
include($page.".htm");
?>
... blah blah ...
</html>
...i've tried this in my htaccess file:
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^products/(.*) /products/index.php?p=$1
Please can someone help me as this is becoming a huge headache!
This is probably fairly easy to someone who knows apache rewrite stuff.
Thank you,
Rob Holmes
I'm trying to get my urls to look like this:
http://www.mydomain.com/products/subproduct/detail
...when the actual file is an html file to be 'include'd in a index.php for example:
http://www.mydomain.com/products/index.php?p=subproduct/detail
...my index.php file would look something like this:
<html>
... blah blah ...
<?php
clearstatcache();
if (file_exists($HTTP_GET_VAR
$page = $HTTP_GET_VARS[p];
echo "The file filename exists";
} else {
$page = 'products';
echo "The file filename does not exist";
}
include($page.".htm");
?>
... blah blah ...
</html>
...i've tried this in my htaccess file:
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^products/(.*) /products/index.php?p=$1
Please can someone help me as this is becoming a huge headache!
This is probably fairly easy to someone who knows apache rewrite stuff.
Thank you,
Rob Holmes
ASKER
Thank you _Blue that really sounded like the answer... so i tried it but still getting page not found. It doesnt even goto the index.php page.
Any ideas?
Rob Holmes
Any ideas?
Rob Holmes
I think it's a problem in what's happening before your rewrite rule gets implemented.
Many apache servers are designed to interpret "http://www.mydomain.com/products/subproduct/detail"
as "http://www.mydomain.com/products/subproduct/detail/"
they automatically add a trailing / and interpret an extensionless value as a directory
try adding a 404 rule to your htaccess
then have the php file it goes to echo $_SERVER['REQUEST_URI']
if that does it, then you can't just use the rewriterule, instead set up an "error" document
Many apache servers are designed to interpret "http://www.mydomain.com/products/subproduct/detail"
as "http://www.mydomain.com/products/subproduct/detail/"
they automatically add a trailing / and interpret an extensionless value as a directory
try adding a 404 rule to your htaccess
then have the php file it goes to echo $_SERVER['REQUEST_URI']
if that does it, then you can't just use the rewriterule, instead set up an "error" document
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi php-webdesign,
I've had a look at phpinfo() and there is no mod_rewrite installed.
I have no access to the server and i dont think the hosting company will implement it for me.
Do i have any other options but to just make the url's like this:
/index.php?p=product
Thanks,
Rob Holmes
I've had a look at phpinfo() and there is no mod_rewrite installed.
I have no access to the server and i dont think the hosting company will implement it for me.
Do i have any other options but to just make the url's like this:
/index.php?p=product
Thanks,
Rob Holmes
no, when mod rewrite is not installed you cannot change the way you call on your page... sorry
(at least not that i know off)
But you can always ask them to install mod-rewrite (or find another hoster ;))
(at least not that i know off)
But you can always ask them to install mod-rewrite (or find another hoster ;))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nice :) didn't know that!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you everyone who was involved with this problem!
I have decided to split the points as there wasn't really a complete solution, but the three guys eeBlueShadow, php-WebDesign and virmajor shared the points as they made major contributions to me making my decision as to what action to take next.
I decided to give eeBlueShadow the accepted answer as the link he has given has really helped me for the future.
Thanks guys!
Rob Holmes
PS speak to you soon because no doubt i'll be back soon.
I have decided to split the points as there wasn't really a complete solution, but the three guys eeBlueShadow, php-WebDesign and virmajor shared the points as they made major contributions to me making my decision as to what action to take next.
I decided to give eeBlueShadow the accepted answer as the link he has given has really helped me for the future.
Thanks guys!
Rob Holmes
PS speak to you soon because no doubt i'll be back soon.
Add the 'Last' flag to the rule and it should work:
RewriteRule ^products/(.*) /products/index.php?p=$1 [L]
_Blue