Rewrite works in .htaccess but does not work in pre_main_global.conf
I am trying to move rewrites from .htaccess files to
/etc/apache2/conf.d/includes/pre_main_global.conf
For testing purposes, the complete content of pre_main_global.conf is:
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "
-
Hey there! I'm not sure that pre_main_global is going to be the appropriate place for those type of redirects. You likely will need to use the individual vhost redirect area, which is at /etc/apache2/conf.d/userdata/ssl/2_4/username/domain.com/*.conf and /etc/apache2/conf.d/userdata/std/2_4/username/domain.com/*.conf. A global include is designed more for things that affect the entire Apache configuration, but I would expect redirects to need to be placed in individual files related to the user. More details on that system can be found here: Modify Apache Virtual Hosts with Include Files | cPanel & WHM Documentation 0 -
Thank you for pointing me in the right direction. When the rewrite shown below is in an .htaccess file and I browse to domain.com/dummy then I am correctly redirected. RewriteOptions inherit RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.domain\.com$ RewriteRule ^dummy$ "http\:\/\/domain\.com\/" [R=301,L] I followed the instructions in the documentation link you posted and made a virtual host conf file for the domain findmesar.com. The only content of that conf file is the above rewrite. I also disabled the .htaccess I rebuilt httpd and restarted apache. The terminal command apachectl -D DUMP_INCLUDES confirms that my new conf file is included in apache Alas, when I tested my virtual host conf file by browsing to findmesar.com/dummy the redirect does not work. I edited the main apache conf file by setting the log level to alert rewrite:trace6 I rebuilt httpd, restarted apache, cleared my browser cache. Then a tried browsing to findmesar.com/dummy hoping that the main apache error.log file would have useful info. Alas, the string "rewrite" does not appear in the main apache error.log file. Below are a few snips from the error.log Obviously I am missing something. Any suggestions? [Wed Jun 22 12:26:22.374365 2022] [core:info] [pid 29045] [client 24.19.223.102:49902] AH00128: File does not exist: /home/username/public_html/domain/dummy [Wed Jun 22 12:26:22.374814 2022] [cgi:error] [pid 29045] [client 24.19.223.102:49902] AH01228: exec used but not allowed in /home/mapping1/public_html/domain/404.shtml [Wed Jun 22 12:26:22.452653 2022] [ssl:debug] [pid 29045] ssl_engine_kernel.c(422): [client 24.19.223.102:49902] AH02034: Subsequent (No.2) HTTPS request received for child 3 (server findmesar.propertylinemaps.com:443), referer: [Wed Jun 22 12:26:23.433624 2022] [ssl:debug] [pid 29045] ssl_engine_kernel.c(422): [client 24.19.223.102:49902] AH02034: Subsequent (No.3) HTTPS request received for child 3 (server host.domain.com:443) [Wed Jun 22 12:26:23.434488 2022] [authz_core:debug] [pid 29045] mod_authz_core.c(844): [client 24.19.223.102:49902] AH01628: authorization result: granted (no directives) [Wed Jun 22 12:26:28.440372 2022] [ssl:debug] [pid 29045] ssl_engine_io.c(1151): [client 24.19.223.102:49902] AH02001: Connection closed to child 3 with standard shutdown (server findmesar.propertylinemaps.com:443) 0 -
Well that's not ideal, that was really all I had for that particular issue. At this point I think it would be worth opening a ticket so we could check out the machine and see what's happening in real-time on your server. 0 -
Ticket submitted 0 -
Solved. The problem was a mistake in my RewriteRule As a test I am trying to get domain.com/dummy to redirect to Website Domain Names, Online Stores & Hosting - Domain.com The following rule does not work RewriteOptions inherit RewriteEngine on RewriteCond %{HTTP_HOST} ^domain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.domain\.com$ RewriteRule ^dummy$ "Website Domain Names, Online Stores & Hosting - Domain.com" [L,R=301,NC] All of the following rules *do* work. RewriteRule /dummy "Website Domain Names, Online Stores & Hosting - Domain.com" [L,R=301,NC] RewriteRule /dummy "https\:\/\/domain\.com" [L,R=301,NC] RewriteRule ^/dummy "https\:\/\/domain\.com" [L,R=301,NC] RewriteRule ^/dummy$ "https\:\/\/domain\.com" [L,R=301,NC] RewriteRule /dummy Website Domain Names, Online Stores & Hosting - Domain.com [L,R=301,NC] The difference is the slash in front of dummy. Tip: Here is how to use WHM to rebuild httpd and then restart apache. Click: apache configuration > Global configuration Scroll to the bottom and click Save Scroll to the bottom and click Rebuild configuration and restart apache 0 -
I'm glad to hear our team was able to help with that! 0
Please sign in to leave a comment.
Comments
6 comments