Pain Posted June 22, 2013 Share Posted June 22, 2013 Hi. I am trying to make my url look more attractive. So far i have managed myweb.com/job.php?ref=333 to make look myweb.com/job?ref=333 How can i shorten it further by making myweb.com/job/333 I have this code RewriteBase / RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^job-([0-9]+)\.php$ job.php?ref=$1 RewriteRule ^job/([a-zA-Z0-9_-]+)/([0-9]+)\.php$ job.php?ref=$2 RewriteRule ^([a-zA-Z0-9_-]+)$ job.php?ref=$1 RewriteRule ^([a-zA-Z0-9_-]+)/$ job.php?ref=$1 thanks for your help:) Quote Link to comment https://forums.phpfreaks.com/topic/279454-short-url-with-mod-rewrite/ Share on other sites More sharing options...
denno020 Posted June 22, 2013 Share Posted June 22, 2013 I'm not sure this is exactly how the htaccess is supposed to be used.. Well it's not how I use it anyway. With my site, I use urls that are "mysite.com/one/two/three". In my htaccess, I grab that url, and rewrite it so it's "mysite.com/index?first=one&second=two&third=three". (I have a MVC setup, so the first one usually corresponds to the controller, the second to the function, and the third is a parameter for that function.) While my htaccess does this rewrite, it doesn't actually change the url that the user sees. So your best bet, I think, is to use your shortened URLs as you want them (make them the hrefs of links/form actions etc) but then write rules that will rewrite them to be job.php?ref=$1 etc. That way you can access 'ref' through $_GET in your php script, but it won't actually change the way that the URL looks to the user.. I really hope that makes sense and I haven't confused you :/.. Denno Quote Link to comment https://forums.phpfreaks.com/topic/279454-short-url-with-mod-rewrite/#findComment-1437385 Share on other sites More sharing options...
Csharp Posted June 22, 2013 Share Posted June 22, 2013 I think you just need this additional rule to get that RewriteRule ^job/([a-zA-Z0-9_-]+)/([0-9]+)$ job.php?ref=$2 Quote Link to comment https://forums.phpfreaks.com/topic/279454-short-url-with-mod-rewrite/#findComment-1437390 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.