Can this be done?
Basically I work on multiple projects using xampp, and I like http://localhost to be the project root ( rather than http://localhost/project_name/ )
Problem is, i have to open the httpd.conf file in the apache folder, change the document root, then restart apache!
I was wondering if this could be done in ms-dos?
say I write a batch file that:
opens the file,
finds the document root,
changes it,
stop apache,
start apache
Then all i would need to do is open the cmd prompt, and write:
http_change.bat new_project_name
Problem is, I only know basic ms-dos and examples and tuition on the web are surprising hard to understand!
EDIT
I’m Really struggling with this so im offering a bounty.
so far i’ve tried:
for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do echo %%a
this successfully reads the file, but then i tried
for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do (
echo %%a
)
and that worked. then
for /f "eol=# tokens=* delims=*" %%a in (httpd.conf) do (
set line=%%a
echo %line%
)
and that failed… it just echoed “ECHO is off.” which makes me assume the it isnt setting the line variable…
my plan was to check each line to see if the first 12 characters == “DocumentRoot” and if they do, rather than saving the line to a new file, i modify the line using sting manipulation and save that instead…
You’re causing yourself unnecessary grief by trying to edit the configuration file. Here’s a better idea:
Remove the
DocumentRootsetting from yourhttpd.conffile. Replace it with anIncludedirective, something like:Now instead of editing a file you simple replace the
documentroot.conffile, which contains a single line of the form:And here’s another idea:
You can pass Apache configuration options on the command line with the
-Cdirective (or-c, depending on whether you want your directive applied before (-C) or after (-c) Apache reads its configuration files). So as with the previous idea, remove the DocumentRoot directive from yourhttpd.conf, and then when you restarthttpd, start it like this: