Topic on Manual talk:Short URL/Apache

Short URL instructions for placing rewrite rule in Apache instead of .htaccess (for tech-morons like me)

1
School4schools (talkcontribs)

Took a while to figure this out, but here are my simpleton's instructions on how to place the re-write directly on Apache instead of using an .htaccess file.

My host is a Virtual Private Network (VPN) which means I have access to CPANEL and WHM

If you do not have access to WHM, this is not for you. Also, these steps are written for Windows users.


NOTE: even though the instructions here say to edit the httpd.conf file directly DO NOT EDIT IT. You will see that at the very bottom of the file it reads:

#  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#   DO NOT EDIT. AUTOMATICALLY GENERATED.  USE INCLUDE FILES IF YOU NEED TO MAKE A CHANGE

#  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

>> there is an editor function in WHM called "Include editor" I could not figure out how to use this, so I used the following steps instead. I'm sure this will drive knowledgeable users crazy, but this is how I managed to get this stupid rewrite on the server without having to use an .htacces file

>> before starting remove an existing .htaccess file and/or remove the commands for short url that may be in it.

>> we are going to give those instructions directly to the Apache server, which will be included in a file called httpd.conf We are NOT going to edit that file directly.


Step 1.

> Go to CPANEL and open File Manager

>> it should open at the /home/accountname/ directory.

>> if not, click on that directory on the left-hand menu of File Manger.

> click on "+ File" on the top menu (to add a file)

> enter a file name with the extension conf

>> any name works, but must have .conf as extension: as in filename.conf

> select that file and click on "Edit"

>> it will be blank. Add to the very top in plaint text, per instructions on this manual, this code:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d

RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]

> "Save" and "Close" the file

Step 2.

> Go to WHM and open "Terminal"

> navigate to the httpd.conf file by using "change directory" commands (cd /)

>> the file should be located on this path: /etc/apache2/conf/

>>> first, navigate to the /etc/ folder by typing cd /etc

>>> then navigate to subfolders from there by typing cd directoryname (such as cd apache2 , then cd conf)

Step 3.

> once you are in the directory /etc/apache2/conf/

>> type dir in order to see the contents of that directory

>> you should see listed there the file htttp.conf

>>>> note that the instructions manual here says it may be called apache2.conf

(<<< btw, those instructions are confusing as it indicates that apache2.conf is a directory whereas it is a file name; in my WHM, which is up to date, it is http.conf )

> now we want to read that file:

> type cat http.conf

<<< "cat" command is for "read file"

>> the file contents will spill across the terminal

>> next, highlight the file contents on the screen using your mouse (start from the bottom, hit left click & hold it while scroll up to the beginning of the file, thus highlighting all the contents)

>>> release the left click button, then right click on the selected text and select "copy"

>>> paste the contents into a plain text editor (I use notepad.exe in Windows)

>>> in the text editor, search for your website name

>>> at the bottom the entry for your website/s it will read something like this:

"  # To customize this VirtualHost use an include file at the following location

  # Include "/etc/apache2/conf.d/userdata/ssl/2_4/accountname/domain/*.conf"

( >> NOTE: if you do not have SSL enabled it that directory will read /std/)

>>> your account name and domain will be already written in that path

> copy that directory path to a new text editor window

Summary so far:

  1. we created a new .conf file using CPANEL at the root of the CPANEL File Manager and wrote the re-write code for short urls.
  2. we identified the correct path to add that file to by reading in WHM terminal, the existing httpd.conf
  3. we copied that path and file name into a text editor.

Step 4.

> type cd to go back to the terminal root directory

>> it looks like root@server.yourprimarydomain.com [~]#

> now we are going to move the file you created in CPANEL to the location that the httpd.conf file told you to place it in order for whm to read and incorporate it into the existing httpd.conf file

> we will use the move command in the terminal: mv

> in your text editor type out the entire move command with the directory paths and file name

>> it should look like this (with your particular account and domain):

mv etc/apache2/conf.d/userdata/ssl/2_4/accountname/domain/filename.conf /etc/apache2/conf.d/userdata/ssl/2_4/accountname/domain/

<< note the single space after "mv" and "filename.conf" (so it reads mv[SPACE]/path/path/filename.conf[SPACE]/path/path

> hit enter

>> this will move the file to the directory that the httpd.conf file told you corresponds to your website

>> if a file with that name is already there, it will ask you to confirm overwriting it. If so, type YES

Step 5.

> now we need to ask Apache to read the file and recompile the httpd.conf fle

> go to the root directory on the terminal

> type /scripts/ensure_vhost_includes --all-users

>> Apache will recompile the httpd.conf file and tell you if this worked or not

Step 6.

> reboot the server

> use "Gentle reboot"

Test out your site and hopefully you're good to go!


(Sadly this does not fix my issue with Visual Editor, which stopped working after I moved to short urls. That would seem to be a problem for another day)

Reply to "Short URL instructions for placing rewrite rule in Apache instead of .htaccess (for tech-morons like me)"