Mod rewrite

kennedypd1
kennedypd1 used Ask the Experts™
on
HI

I am just starting out using this and thought I had my head around it so was just trying to do the most basic task but not working and I dont understand why.

.htaccess

RewriteEngine On    # Turn on the rewriting engine
RewriteRule ^items-starting-with-a/$   browse_categories.php?search_string=A    [NC,L]    # Handle requests for "A"

URL
http://domain.com/items-starting-with-a/

Server Error
The requested URL /var/users/userid/domain.com/htdocs/browse_categories.php was not found on this server.

Checked
manually type in domain.com/browse_categories.php and it delivers the page fine as does domain.com/browse_categories.php?search_string=A

Anyone got any ideas where I am heading wrong here
Any help appreciated
Paul
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
It appears that the Rewrite Rule created a file path instead of a URL.  The URL would start with something like https://  Instead we got something like /var/users/userid/domain.com/htdocs/ which appears to be the server file path to the web root.

This article is old, but SitePoint is usually a pretty good learning resource.  Check examples 8, 9, 11.
http://www.sitepoint.com/apache-mod_rewrite-examples-2/

Also, if you're using a hosting company, ask their tech support for an example.  You are not the first one to ask this question, and it's probably part of their library of Q-n-A!

Author

Commented:
Hi Ray

Thanks I have worked it out.

I had to change the rule to have a slash infront of the page name like below.

RewriteEngine On    # Turn on the rewriting engine
RewriteRule ^items-starting-with-a/$   /browse_categories.php?search_string=A    [NC,L]    # Handle requests for "A"

Cheers
Paul
Most Valuable Expert 2011
Top Expert 2016

Commented:
Looks good!  Thanks for the points, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial