• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

.htaccess - putting redirects in an external/include file

They are making page name changes and setting up redirects on this one site I am managing. I would like to set it up so they can put in their own redirects for Apache as they need but I do not want them getting into the .htaccess file - too risky! Is there away to put all the redirects in a single file that I can let them edit? I thought that the mapping features might work but I don't know enough to do it correctly.

Any help greatly appreciated!

The code below is a sample redirect. Note the escaped character, the solution needs to be able to handle such characters at times.
RewriteRule ^don\'t-be-penny-wise-and-pound-foolish$ http://%{HTTP_HOST}/dont-be-penny-wise-and-pound-foolish [R=301,L,NS]

Open in new window

0
RegProctor
Asked:
RegProctor
  • 5
  • 3
1 Solution
 
caterham_wwwCommented:
You can't include external files into .htaccess files.

What you could do: Write a script which analyzes an external file and - if the directives are ok for you/passes the check - write a new .htaccess file.
0
 
RegProctorAuthor Commented:
Surely there is a way to use RewriteMap after all it is a Rewrite function. I'm just not familiar enough with Apache Rewrite to figure it out.
0
 
caterham_wwwCommented:
If you have access to the httpd.conf in order to define one, yes
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RegProctorAuthor Commented:
Yes I do.
0
 
RegProctorAuthor Commented:
Can you give me an example on how to make this work with the above redirect.
0
 
caterham_wwwCommented:
Yes, of course.
RewriteEngine on
RewriteMap lookup txt:/var/www/full/path/map.txt
RewriteCond ${lookup:$1} ^(.+)
RewriteRule ^/(.*) http://%{HTTP_HOST}/%1 [R=301,L,NS]
 
 
You'll need a text file like
 
# lookup substitute
don't-be-penny-wise-and-pound-foolish dont-be-penny-wise-and-pound-foolish
a b
foo bar

Open in new window

0
 
RegProctorAuthor Commented:
Works like a charm, thanks!
0
 
RegProctorAuthor Commented:
Great solution.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now