LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-19-2014, 11:42 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 54

Rep: Reputation: 15
Arrow mod_rewrite RewriteRule


hi

I need to redirect using mod_rewrite this type of url
http://mysite.com/user/index.php?id=23322

to this:
http://mysite.com/archive/old_user/index.php?id=23322

I need it to NOT display the destination url to the user's browser so the user thinks he is still in the previous one. (he needs to see "user" not "archive/old_user"

searching this topic I think this will do it:
Code:
RewriteEngine on
RewriteBase /
RewriteRule   ^/user/(.*) /archive/old_user/$1 [P,L]
or

Code:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/archive/old_user/
RewriteRule   ^/user/(.*) /archive/old_user/$1 [P,L]
are those correct ? which one is better ? which one is safer ? which one will load less on the server/apache ?

also does anybody know a good online mod_rewrite tool that you can input the url, the mod_rewrite syntax and than it gives you result ?

Last edited by basher400; 10-19-2014 at 11:48 AM.
 
Old 10-19-2014, 05:23 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
They are correct but the second will only apply if the URL doesn't starts with "archive/old_user"

I don't think you want this as it seems you want to keep the archive/old_user/* urls private, no?

Code:
RewriteBase /
RewriteRule ^/user/(.*) /archive/old_user/$1 [END]
RewriteRule ^/archive/old_user - [R=404]
This should send a 404 error page if one try to access http://mysite.com/archive/old_user/* directly
 
Old 10-20-2014, 04:20 AM   #3
basher400
Member
 
Registered: Mar 2005
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by keefaz View Post
They are correct but the second will only apply if the URL doesn't starts with "archive/old_user"

I don't think you want this as it seems you want to keep the archive/old_user/* urls private, no?
no , i don't want to keep them private.
i just want to redirect one to the other and I want it with less load on the server/apache as possible.
 
Old 10-20-2014, 06:15 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Code:
RewriteRule ^/user/(.*) /archive/old_user/$1 [L]
Seems efficient enough (will certainly load the server much less than php script)

Or maybe use Alias if you have access to server config files (doesn't work in .htaccess)

Last edited by keefaz; 10-20-2014 at 06:18 AM.
 
  


Reply

Tags
mod_rewrite, rewriterule


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on RewriteRule circus78 Linux - Server 1 08-08-2014 06:17 AM
RewriteRule probem web_questions Linux - Networking 2 10-04-2012 02:49 PM
Apache RewriteRule help danster3k Linux - Server 3 10-06-2010 02:35 AM
Apache RewriteRule does not do what I want? Ujjain Linux - Server 0 03-26-2009 08:46 AM
Apache rewriterule mesh2005 Linux - Server 1 08-03-2007 03:23 AM


All times are GMT -5. The time now is 12:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration