Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.