thara Posted July 29, 2012 Share Posted July 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/ Share on other sites More sharing options...
requinix Posted July 29, 2012 Share Posted July 29, 2012 Does tutors/index.php require the city name? If so then you have to put that in the new URL too, or adjust the code so that it isn't necessary. Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1365312 Share on other sites More sharing options...
thara Posted July 30, 2012 Author Share Posted July 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1365326 Share on other sites More sharing options...
thara Posted October 3, 2012 Author Share Posted October 3, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1382522 Share on other sites More sharing options...
requinix Posted October 3, 2012 Share Posted October 3, 2012 No changes? Since apparently the city is required, where do you want it to show up in the new URL? Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1382549 Share on other sites More sharing options...
thara Posted October 6, 2012 Author Share Posted October 6, 2012 (edited) 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. Edited October 6, 2012 by thara Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1383169 Share on other sites More sharing options...
requinix Posted October 6, 2012 Share Posted October 6, 2012 (edited) Okay... Well, if you don't want the slash then change the two RewriteRules so that they use the URL format you want. Edited October 6, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1383177 Share on other sites More sharing options...
thara Posted October 6, 2012 Author Share Posted October 6, 2012 I am really no idea how to do it... can you explain it with an example? I removed ending slash of the URL that display on web browser's address bar, then my URL is not working. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1383185 Share on other sites More sharing options...
requinix Posted October 6, 2012 Share Posted October 6, 2012 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). Quote Link to comment https://forums.phpfreaks.com/topic/266409-url-rewriting-help/#findComment-1383374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.