LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 05-05-2015, 02:06 PM   #1
brunofontaine
LQ Newbie
 
Registered: May 2015
Posts: 2

Rep: Reputation: Disabled
What does this rewrite rule actually do?


When looking at .htaccess on our server, I see that the developers included the following lines:

RewriteRule (services/.*) $1 [L] # adjust the regex to what you want.
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

No idea what the first RewriteRule actually does
Not sure about the ^$ in the 2nd rule
I understand the 3rd rule.


I would appreciate a quick explanation. Thank you very much in advance.

Last edited by brunofontaine; 05-05-2015 at 02:34 PM.
 
Old 05-05-2015, 06:31 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
In regex ^ anchors to the start of a line, $ anchors to the end of a line, so ^$ matches the empty line.
 
1 members found this post helpful.
Old 05-06-2015, 05:04 AM   #3
Tim Abracadabra
Member
 
Registered: May 2014
Location: USA, Wherever I may Roam
Distribution: debian 9.8 w/GNOME and KDE dual boot w/Win 10.| debian 7.11 w/Xfce, LFS 7.9, + Multi-boot w/Windows7
Posts: 122

Rep: Reputation: Disabled
Hi brunofontaine and welcome to LQ!

Regarding the first RewriteRule:
Code:
RewriteRule (services/.*) $1 [L] # adjust the regex to what you want.
(services/.*) is the pattern match so matches against a directory or url path
that (minus the domain name) includes and ends with services/

The .* that follows matches any single character and any that follow it.

The $1 in this case is the target and is a variable that holds the value matched in the parenthesis.

Examples:

services/myapp.php will select the target services/myapp.php and if found will return that to the requestor.

myandroidservices/myapp.php however will still select the target services/myapp.php and again if found will return that to the requestor.

Note that in a browser the URL will not change to the target even if it is different
as in the second example as this particular rule is a essentially mapping function and not a redirect.

Here is more info on Mod_Rewrite.

Hope that helps,

Tim

Last edited by Tim Abracadabra; 05-06-2015 at 05:18 AM. Reason: Add browser note
 
1 members found this post helpful.
Old 05-06-2015, 06:23 PM   #4
brunofontaine
LQ Newbie
 
Registered: May 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you.

Thank you for your detailed replies. Very informative.
 
  


Reply



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
apache rewrite rule sunlinux Linux - Newbie 10 11-11-2011 05:01 AM
htaccess rewrite rule asifbasha Linux - Server 1 09-21-2011 12:48 PM
need on rewrite rule help ravibhure Linux - Newbie 5 09-09-2010 01:03 PM
apache2 rewrite rule help razzera Linux - Server 7 08-17-2010 04:39 PM
i need a rewrite rule!help arcow Linux - Enterprise 1 07-03-2007 05:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:36 AM.

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
Open Source Consulting | Domain Registration