Jump to content

URL rewriting help


thara

Recommended Posts

Hello everyone..

 

In my website there is a link to registered tutors. That link is something like this

 

http://www.lankainstitute.com/profiles/tutors/index.php?tutorCode=1285&tutorName=Shamdhi%20Samaranayake&city=Pelmadulla

 

So I need to rewrite this link something like this...

 

www.lankainstitute.com/1285/Shamdhi Samaranayake

 

Can anybody tell me is it possible to rewrite above original URL to my expecting URL???

 

any comments are greatly appreciated.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/266409-url-rewriting-help/
Share on other sites

Yes.. It need to index.php page.. can you help me to do this work.. I got this and tried with this it work for me but city variable and value display at the end in my pretty url. How can I take away this city from the URL. As well as there is an another case in my index.php file, then it is now my profile/tutor/index.php file can't identify my css file. I placed it into this 'profile/styles/file.css'

 

RewriteEngine On

# check if the actual request if for "this1"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/tutors/index.php\?tutorCode=([0-9]+)&tutorName=([^&]+)&?([^\ ]+)
# redirect to "this2"
RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE]

# now rewrite "this2" back to "this1"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?tutorCode=$1&tutorName=$2 [L,QSA]

any comments are greatly appreciated. 

Thank You.

Link to comment
https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1365326
Share on other sites

  • 2 months later...

RewriteEngine On
# check if the actual request if for "this1"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/tutors/index.php\?tutorCode=([0-9]+)&tutorName=([^&]+)&?([^\ ]+)
# redirect to "this2"
RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE]
# now rewrite "this2" back to "this1"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?tutorCode=$1&tutorName=$2 [L,QSA]

 

any comments are greatly appreciated.

 

Thank You.

Link to comment
https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1382522
Share on other sites

thanks for response..

 

I need to show up my new URL in browser's address bar.

 

I blocked city value from $_POST array and now only 2 values come to tutor profile page ('tutor code & tutor name'). Then Its working for me and now my tutor profile's new url display something like this 'http://www.mydomain....tutorCode/Tutor Name/'.

 

In this case, There is a backslash '/' printing at the end of my new URL. So can I know, it is possible to disapear the ending backslash from my new URL or If it is not possible can I add .html file extention to my new URL.? Then it should be something like this http://www.mydomain....Tutor Name.html

 

any comments are greatly appreciated.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1383169
Share on other sites

There's two parts that deal with trailing slashes.

# redirect to "this2"
RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE]

That "/%1/%2/?%3" includes a trailing slash (just before the ?).

 

The other is

RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?tutorCode=$1&tutorName=$2 [L,QSA]

The "^([0-9]+)/(.+)/$" requires a trailing slash.

 

It's as simple as removing the slashes. And fixing whatever links you output to not include them (if you haven't already).

Link to comment
https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1383374
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.