Jump to content

short url with mod rewrite


Pain

Recommended Posts

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:)

 

Link to comment
https://forums.phpfreaks.com/topic/279454-short-url-with-mod-rewrite/
Share on other sites

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

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.