Beruflich Dokumente
Kultur Dokumente
htaccess Redirects and Rewrites
Last updated by lucero@uark.edu 8/11/2015
Here is an elegant way to configure an .htaccess file to redirect and/or rewrite the URL for any given
resource or web page in OU. Using these examples will make it so that user does not need to create the
directories of the path for the first requested resource.
For more information on URL rewriting, please read https://www.addedbytes.com/articles/for‐
beginners/url‐rewriting‐for‐beginners/.
Firstly, with .htaccess, regular expressions can be used for matching. For more information on that,
please read http://www.webforgers.net/mod‐rewrite/mod‐rewrite‐syntax.php.
This example uses an htaccess file from honorscollege.uark.edu, and the .htaccess file is placed in the
root of the site.
RewriteEngine On
RewriteRule ^265.php /prospective-students/fellowships/fellowship-
application-checklist.php [R=301,L]
RewriteRule ^convocation(/)?$ /prospective-students/visit-us/honors-college-
convocation.php [R=301,L]
RewriteRule ^study-abroad-grants(/)?$ /current-students/study-abroad-
grants/index.php [R=301,L]
RewriteRule ^invites(/)?$ /engage/honors-college-invites.php [R=301,L]
RewriteRule ^biomedical(/)?$ /prospective-students/meet-the-students/katelin-
cherry.php [R=301,L]
The following is a line by line explanation:
Line 1: RewriteEngine On
This (Rewrite On) must be the first line to enable the Rewrite Engine on the Apache server.
Lines 2 & 3:
RewriteRule ^265.php /prospective‐students/fellowships/fellowship‐application‐checklist.php [R=301,L]
^ signifies the beginning of the line (after the host name, e.g., honorscollege.uark.edu/)
RewriteRule specifies that any request for the first resource will redirect a user to the second resource
on the same site, while specifying this as a permanent redirect(R=301) and to signify(L) the ‘end’ or ‘exit
now’ for processing this particular rule
Lines 3 & 4:
RewriteRule ^convocation(/)?$ /prospective‐students/visit‐us/honors‐college‐convocation.php
[R=301,L]
^ signifies the beginning of the line (after the host name, e.g., honorscollege.uark.edu/)
(/)?$ means to match either a slash or not, e.g., the rule will match a request for
“honorscollege.uark.edu/convocation” or “honorscollege.uark.edu/convocation/”
Lastly, if [R=301,L] is left off of any of the above rules, then the URL that shows in the user’s browser
address bar will not be rewritten according to the resource to which the user is redirected. Instead, the
URL in the browser address bar will remain as the original request. For example, if this rule existed in
the .htaccess file (notice no “[R=301,L]” at the end of the line):
RewriteRule ^test(/)?$ /index.php
The result is that any request for “honorscollege.uark.edu/test” or “honorscollege/test/” will redirect to
“honorscollege.uark.edu/index.php”, however the URL in the browser address bar will remain
“honorscollege.uark.edu/test” or “honorscollege/test/” (whichever was originally requested by the
user). This type of configuration can be useful for campaigns or ‘short/friendly URLs’ or in any situation
whereby site authors may want the ‘short’ URL to persist so as not to confuse the user. (Otherwise, the
less experienced user may be confused and think, “I’m supposed to go to “honorscollege.uark.edu/test”,
but when I go there, I get redirected to “honorscollege.uark.edu/index.php”. Am I still at the correct
webpage???”