Jump to content
Larry Ullman's Book Forums

Url Rewriting Help


Recommended Posts

hi.. everyone..

 

I need to rewrite this URL

 

http://localhost/lanka_institute/profiles/tutors/index.php?tutorCode=1255&tutorName=Kasun%20Perera&city=Bandarawela

like this

 

http://www.mydomain.com/profiles/tutors/1255/Kasun+Perera.html

 

I tried this with Apache’s mod_rewrite feature. But I couldn't reach to my expecting result.

 

Here is Code that I have tried.

 

<IfModule mod_rewrite.c>
RewriteEngine on
# For specific teachers:
RewriteRule ^localhost/lanka_institute/profiles/tutors/([0-9]+)/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/$ index.php?tutorCode=$1&tutorName=$2&city=$3
</IfModule>

 

It is not working and then I can get this error message.

 

Internal Server Error

 

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

 

 

any comments are greatly appreciated.

 

Thank you.

Link to comment
Share on other sites

Okay, first, are you really trying to redirect from localhost to another domain? And are you trying to redirect from one subdirectory (lanka_institute/profiles) to a different subdirectory (profiles)? And where are you putting your .htaccess file?

Link to comment
Share on other sites

thanks for response...

 

I am not going to redirect to another domain. sorry for my incomplete and unclear question. actually Im going to do is a dynamically generated url convert to frienly url.

 

this is php generated url..

 

http://localhost/tutor_institute/profiles/tutors/index.php?tutorCode=1255&tutorName=Jhon Amarathunga&city=Perth

 

I need to rewrite it like this

 

http://localhost/tutor_institute/profiles/tutors/1255/Perth/Jhon Amarathunga.html

 

My index.php page dynamically generate more teacher's profile in my website. Thats why I need to rewrite that url to a friendly format.

 

the path to my index.php file from the server's root directory is 'tutor_institute/profiles/tutors/index.php'

tutor_institute,profiles and tutors are sub folders in my root directory.

 

In my home page there are links to all tutor profiles generated by system. It link is something like this..

 

echo '<h2><a href="profiles/tutors/index.php?tutorCode=' . $row3['tutor_code'] . '&tutorName=' . $row3['tutor_name'] . '&city=' . $row3['city_name'] . '">' . $row3['tutor_name'] . '</a></h2>';

 

This is from my .htaccess file and I have placed .htaccess file in to 'tutors' sub directory which contain my index.php file.

 

RewriteEngine on
RewriteRule ^/profiles/tutors/([0-9]+)/([A-Za-z_]+)/([A-Za-z_]+)$ index.php?tutorCode=$1&tutorName=$2&city=$3 [NC]

 

 

Thank you

Link to comment
Share on other sites

Okay. I'd start by adding this line after RewriteEngine on:

RewriteBase tutor_institute/profiles/tutors/

 

This way you only need to do redirects from that part of the URL on.

 

Then I'd try a sample rewrite, just to confirm that rewrites are working at all:

RewriteUrl ^test.html index.php

 

Then you should be able to go to your url/test.html and be shown the index page.

Link to comment
Share on other sites

Actually I cant understand what I need to do with your answer. sorry for my little knowledge of the subject. Any way I change my .htaccess file like this

 

RewriteEngine on
RewriteBase tutor_institute/profiles/tutors/
RewriteRule ^/profiles/tutors/([0-9]+)/([A-Za-z_]+)/([A-Za-z_]+)$ index.php?tutorCode=$1&tutorName=$2&city=$3 [NC]

 

but nothing happen.. if you can elaborate your solution, It will help me understand the subjects.

 

any comments are greatly appreciated.

 

thank you.

Link to comment
Share on other sites

I change .htaccess file like this

 

RewriteEngine on
RewriteBase tutor_institute/profiles/tutors/
RewriteUrl ^test.html index.php

 

Create test.html file and placed it in tutors sub directory which is my index.php file exist.

 

typed url in address bar, its like this

 

http://localhost/lanka_institute/profiles/tutors/test.html

 

Now I can get this massege in browser window.

 

Internal Server Error

 

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

 

 

page title display

 

500 intenal server errors

 

 

where I am going wrong????

 

Thank you

Link to comment
Share on other sites

It'd help if you were more consistent. Is the first directory lanke_institute or tutor_institute? You've used both in this post. Which ever is correct, use that in your htaccess and your browser URL.

Link to comment
Share on other sites

Yes.. I used tutor_institute directory and sometimes used lanka_institute directory too for experiments porpose. when I use both directories I did it correctly in my htaccess and browser url. But still I couldn't it to get working. actually what has happend there... I followed more online tutorials to subject and all of them are fomfort for me. but I cant get it work in my project...

 

any comments are greatly appreciated.

 

Thank you..

Link to comment
Share on other sites

 Share

×
×
  • Create New...