Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-23-2011, 01:14 PM   PM User | #1
nirajmchauhan
New Coder

 
Join Date: Sep 2010
Location: India
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
nirajmchauhan is an unknown quantity at this point
htaccess and url rewrite help

Hello everyone,

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

Code:
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?
nirajmchauhan is offline   Reply With Quote
Old 04-23-2011, 02:54 PM   PM User | #2
kgb
New to the CF scene

 
Join Date: Aug 2009
Posts: 7
Thanks: 0
Thanked 2 Times in 2 Posts
kgb is an unknown quantity at this point
Backup your current configuration of the .htaccess and use the config below:

Code:
RewriteEngine On
Options +Followsymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.* - [L]
RewriteRule ^.*/images/(.*)$ /images/$1 [L]
RewriteRule ^.*/uploads_user/(.*)$ /uploads_user/$1 [L]
RewriteRule ^([^/]+)/?$ /profile.php?user=$1 [L]
RewriteRule ^([^/]+)/([^/]+)?$ /profile.php?user=$1$2 [L]
RewriteRule ^([^/]+)/documentgroups/([0-9]+)/([0-9]+)/([^/]+)/?$ /documentgroup.php?user=$1&documentgroup_id=$2&group_id=$3&title=$4 [L]
RewriteRule ^([^/]+)/documentgroups/([0-9]+)/([^/]+)?$ /documentgroup.php?user=$1&documentgroup_id=$2$3 [L]
RewriteRule ^([^/]+)/documents/([0-9]+)/([^/]+)/?$ /document.php?user=$1&document_id=$2&title=$3 [L]
RewriteRule ^([^/]+)/documents/([0-9]+)/([^/]+)?$ /document.php?user=$1&document_id=$2$3 [L]
RewriteRule ^([^/]+)/documents/?$ /documents.php?user=$1 [L]
RewriteRule ^([^/]+)/documents/?$ /documents.php?user=$1 [L]
RewriteRule ^documents/tag/([^/]+)/?$ /browse_documents.php?tag=$1 [L]
RewriteRule ^documents/category/([0-9]+)/?$ /browse_documents.php?i=$1 [L]
RewriteRule ^([^/]+)/blog/([0-9]+)/?$ /blog.php?user=$1&blogentry_id=$2 [L]
RewriteRule ^([^/]+)/blog/([^/]+)?$ /blog.php?user=$1$2 [L]
RewriteRule ^([^/]+)/blog/?$ /blog.php?user=$1 [L]
RewriteRule ^([^/]+)/trackback/([0-9]+)/?$ /blog_ajax.php?task=trackback&user=$1&blogentry_id=$2 [L]
RewriteRule ^([^/]+)/videos/([0-9]+)/?$ /video.php?user=$1&video_id=$2 [L]
RewriteRule ^(.*/)?group/([0-9]+)/([^/]*)$ /group.php?group_id=$1$2$3 [L]
RewriteRule ^(.*/)?group/([0-9]+)/album/([0-9]+)/([^/]*)$ /group_album_file.php?group_id=$2&groupmedia_id=$3$4 [L]
RewriteRule ^(.*/)?group/([0-9]+)/discussion/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$2&grouptopic_id=$3$4 [L]
RewriteRule ^(.*/)?group/([0-9]+)/discussion/([0-9]+)/([0-9]+)/([^/]*)$ /group_discussion_view.php?group_id=$2&grouptopic_id=$3&grouppost_id=$4$5 [L]
RewriteRule ^([^/]+)/articles/([^/]+)?$ /articles.php?user=$1$2 [L]
RewriteRule ^([^/]+)/articles/?$ /articles.php?user=$1 [L]
RewriteRule ^article/([0-9]+)(/[^/]*)?$ /article.php?article_id=$1&article_slug=$2 [L]
RewriteRule ^([^/]+)/job/([0-9]+)/?$ /job.php?user=$1&jobentry_id=$2 [L]
RewriteRule ^([^/]+)/job/([^/]+)?$ /job.php?user=$1$2 [L]
RewriteRule ^([^/]+)/job/?$ /job.php?user=$1 [L]
RewriteRule ^([^/]+)/trackback/([0-9]+)/?$ /job_ajax.php?task=trackback&user=$1&jobentry_id=$2 [L]
RewriteRule ^([^/]+)/classifieds/([0-9]+)/?$ /classified.php?user=$1&classified_id=$2 [L]
RewriteRule ^([^/]+)/classifieds/([0-9]+)/([^/]+)?$ /classified.php?user=$1&classified_id=$2$3 [L]
RewriteRule ^([^/]+)/classifieds/?$ /classifieds.php?user=$1 [L]
RewriteRule ^(.*/)?event/([0-9]+)/([^/]*)$ /event.php?event_id=$1$2$3 [L]
RewriteRule ^(.*/)?event/([0-9]+)/album/([0-9]+)/([^/]*)$ /event_album_file.php?event_id=$2&eventmedia_id=$3$4 [L]
RewriteRule ^application/([0-9]+)/?$ /app.php?id=$1 [L]
RewriteRule ^institutes/([0-9]+)$ /institutes_desc.php?id=$1 [L]

Example urls would be http://yoursite.com/institutes/1 , http://yoursite.com/institutes/2, 3 and so on.

Last edited by kgb; 04-23-2011 at 03:00 PM..
kgb is offline   Reply With Quote
Old 04-23-2011, 04:33 PM   PM User | #3
nirajmchauhan
New Coder

 
Join Date: Sep 2010
Location: India
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
nirajmchauhan is an unknown quantity at this point
not working, it still shows me the old URL
nirajmchauhan is offline   Reply With Quote
Old 04-23-2011, 04:46 PM   PM User | #4
kgb
New to the CF scene

 
Join Date: Aug 2009
Posts: 7
Thanks: 0
Thanked 2 Times in 2 Posts
kgb is an unknown quantity at this point
You should change the links in your website code to point to the new destination.

Look for something like <a href="mysite.com/institutes_desc.php?id=$SomeVar">probably some text</a> and change it to <a href="mysite.com/institutes/$SomeVar"></a>

http://yoursite.com/institutes/19

Also copy the link above, replace yoursite.com with the actual sub/domain of the website in question, paste the link with the replaced url in your browsers address bar and try to open it.
kgb is offline   Reply With Quote
Old 04-24-2011, 06:51 AM   PM User | #5
nirajmchauhan
New Coder

 
Join Date: Sep 2010
Location: India
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
nirajmchauhan is an unknown quantity at this point
I have too many pages with this URL,
If I keep on editing each of them, then it will be longggg

Their is no other way so that all that will be redirected to the new URL?
nirajmchauhan is offline   Reply With Quote
Old 04-25-2011, 06:25 AM   PM User | #6
nirajmchauhan
New Coder

 
Join Date: Sep 2010
Location: India
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
nirajmchauhan is an unknown quantity at this point
Smile

Quote:
Originally Posted by kgb View Post
You should change the links in your website code to point to the new destination.

Look for something like <a href="mysite.com/institutes_desc.php?id=$SomeVar">probably some text</a> and change it to <a href="mysite.com/institutes/$SomeVar"></a>

http://yoursite.com/institutes/19

Also copy the link above, replace yoursite.com with the actual sub/domain of the website in question, paste the link with the replaced url in your browsers address bar and try to open it.
In URL when I type then the page opens,
but I cant edit all files with this URL,
Is their any htaccess rule, where all old URLS will be directed to the new one?
nirajmchauhan is offline   Reply With Quote
Reply

Bookmarks

Tags
.htaccess, mod_rewrite, url_rewrite

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:05 AM.


Advertisement
Log in to turn off these ads.