Link to home
Start Free TrialLog in
Avatar of Lightwalker
Lightwalker

asked on

Creating tidy URL's using htaccess and php script included

Dear Experts,

I am having trouble getting clean url's on my files. I understood that it was complex to do and so I wanted to make it as easy as possible. I purchased a script which is designed to make it easy but I found the help documents hard to understand and was hoping to get some guidance. I have included the files and documentation with this request. The author of the script is away on holiday and so I can not ask for his help.

The script came from here http://codecanyon.net/item/mod-rewriter/79439

I am wanting to change a url from:

http://curalarge/member/support/ticket.php?r=13

to

http://curalarge/member/support/ticket/13/

which this script promised to do with ease. I got frustrated and has another go with a different method which was this in the .htaccess file

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^member/support/ticket/([0-9]+)/?$   member/support/ticket.php?r=$1    [NC,L]    # Handle product requests

This method when I go to http://curalarge/member/support/ticket/13/ strips out the css and some of the dynamic content.

I am using this on a testing server using MAMP.

If anyone could put together a working example from the script for the URL I included above I will be very grateful.

All files that have a description starting with Demo 1 are the demo that was provided for me to learn from.

Thank you as always help.html install.php Routing.php important.txt index.php home.php news.php profile.php Routing.php install.php
Avatar of HackneyCab
HackneyCab
Flag of United Kingdom of Great Britain and Northern Ireland image

Your effort looks close, but you may need to be more specific with the target by adding a forward slash:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^member/support/ticket/([0-9]+)/?$   /member/support/ticket.php?r=$1    [NC,L]    # Handle product requests

Without this forward slash, the rewrite will rewrite paths based on the directory of the current path, which may not be the root directory in the case of CSS files, etc.
Avatar of Lightwalker
Lightwalker

ASKER

Hi HackneyCab,

I am afraid the same thing occurs. The css has been stripped out
Sorry, half asleep here.

The problem is that your page is actually located in a script at /member/support/ but the web browser thinks the visitor is on a page located at /member/support/ticket/13/ so any relative paths in your HTML (paths which don't begin with either "http:" or a forward-slash representing the document root) will no longer point to the correct place, so the web browser will ask for files from the wrong directories.

You can either create rewrite rules which correct this, or you can make your CSS, image, and page links absolute or root-anchored paths (beginning with "http:" or a forward-slash representing the document root).
Thanks, that makes sense, my problem is. being on a testing server if I change my paths to be absolute. when I upload them to my actual server I will have to change them again to the domain name. To add insult to injury this is a redesign and will be hosted on a new server and will need to be tested using the IP address until it is ready and I can change the DNS which mean I might have to change the paths 3 times.

Is there a way in PHP that it can always looks up the root directory or is there a better way where I won't have to change it 3 times for all pages

Many thanks again
ASKER CERTIFIED SOLUTION
Avatar of HackneyCab
HackneyCab
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
very helpful