1

I have a social engine 3 website, in my website all URLS can be changed(URL-REWRITING) through the SE-url settings automatically, but in my website their is one module which is custom coded, where I have to set its URL manually in htaccess file,

the url which I want to changes is this:

mysite.com/institutes_desc.php?id=19

I want this URL to be changed like

mysite.com/institutes/intitute_name or mysite.com/institutes/intitute_id

My htaccess file is this

RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*/images/(.*)$ /images/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*/uploads_user/(.*)$ /uploads_user/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /profile.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)?$ /profile.php?user=$1$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/documentgroups/([0-9]+)/([0-9]+)/([^/]+)/?$ /documentgroup.php?user=$1&documentgroup_id=$2&group_id=$3&title=$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/documentgroups/([0-9]+)/([^/]+)?$ /documentgroup.php?user=$1&documentgroup_id=$2$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/documents/([0-9]+)/([^/]+)/?$ /document.php?user=$1&document_id=$2&title=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/documents/([0-9]+)/([^/]+)?$ /document.php?user=$1&document_id=$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/documents/?$ /documents.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/documents/?$ /documents.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^documents/tag/([^/]+)/?$ /browse_documents.php?tag=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^documents/category/([0-9]+)/?$ /browse_documents.php?i=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/blog/([0-9]+)/?$ /blog.php?user=$1&blogentry_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/blog/([^/]+)?$ /blog.php?user=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/blog/?$ /blog.php?user=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/trackback/([0-9]+)/?$ /blog_ajax.php?task=trackback&user=$1&blogentry_id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/videos/([0-9]+)/?$ /video.php?user=$1&video_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/([^/]*)$ /group.php?group_id=$1$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/album/([0-9]+)/([^/]*)$ /group_album_file.php?group_id=$2&groupmedia_id=$3$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/discussion/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$2&grouptopic_id=$3$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?group/([0-9]+)/discussion/([0-9]+)/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$2&grouptopic_id=$3&grouppost_id=$4$5 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/articles/([^/]+)?$ /articles.php?user=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/articles/?$ /articles.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/([0-9]+)(/[^/]*)?$ /article.php?article_id=$1&article_slug=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/job/([0-9]+)/?$ /job.php?user=$1&jobentry_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/job/([^/]+)?$ /job.php?user=$1$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/job/?$ /job.php?user=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/trackback/([0-9]+)/?$ /job_ajax.php?task=trackback&user=$1&jobentry_id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/classifieds/([0-9]+)/?$ /classified.php?user=$1&classified_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/classifieds/([0-9]+)/([^/]+)?$ /classified.php?user=$1&classified_id=$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/classifieds/?$ /classifieds.php?user=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?event/([0-9]+)/([^/]*)$ /event.php?event_id=$1$2$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?event/([0-9]+)/album/([0-9]+)/([^/]*)$ /event_album_file.php?event_id=$2&eventmedia_id=$3$4 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^application/([0-9]+)/?$ /app.php?id=$1 [L]

Can anyone help me in this? how can I set my url this way?

2

I'll assume that institute IDs have to be integers - no letters or decimal points or anything.

# Turn on URL re-writing
RewriteEngine On

# Clean URLs for institutes.
RewriteRule ^institutes/([0-9]+)/?$   /institutes_desc.php?id=$1    [NC,L]

For further information, I refer you to Dave Childs' thorough introduction to URL rewriting.

  • hey, this helped me, the urls are working now, but the problem is I have to manually put this URL in address bar and check, if I click the link, then still it shows the old URL, is their any htaccess rule, where automatically old URLS will be redirected to the new one? – Niraj Chauhan Apr 25 '11 at 5:31
  • @Niraj Chauhan Try a 301 redirect, using a regular expression to pull the ID. Thus: RedirectMatch 301 /institutes_desc.php?id=([0-9]+) http://mysite.com/institutes/$1 -- and note that the second bit MUST have the full URL of your site, starting with the HTTP. EDIT: Oh, and if you can, it would be better to fix the links in the pages. The 301 redirect will let old URLs still work, but it slows down page load a teeny bit because it adds an extra HTTP request (the redirect). – Will Martin Apr 25 '11 at 21:06
  • @NirajChauhan "if I click the link, then still it shows the old URL" - You still have to actually change the URL in your application. The rewrite above simply allows the new URL to work. – MrWhite Oct 30 '19 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.