{"id":11419,"date":"2025-04-30T12:31:19","date_gmt":"2025-04-30T06:46:19","guid":{"rendered":"https:\/\/nestnepal.com\/blog\/?p=11419"},"modified":"2026-06-22T11:56:50","modified_gmt":"2026-06-22T11:56:50","slug":"enable-cors-in-cpanel-for-cross-domain-access","status":"publish","type":"post","link":"https:\/\/nestnepal.com\/blog\/enable-cors-in-cpanel-for-cross-domain-access\/","title":{"rendered":"How to Enable CORS in cPanel: A Complete Guide for Cross-Domain Access"},"content":{"rendered":"
<\/p>\n
If your website needs to fetch data from external APIs or other domains, you’ve likely run into Cross-Origin Resource Sharing (CORS)<\/a> errors. CORS is a browser security feature that restricts cross-origin HTTP requests. To enable your site to communicate with different origins, like pulling data from a third-party service, you\u2019ll need to manually configure your server to allow such requests.<\/span><\/p>\n <\/p>\n This guide will walk you step by step through enabling CORS in your cPanel-hosted website using the `.htaccess` file. Whether you’re working with JavaScript front-ends, APIs, or single-page applications (SPAs), this method is crucial for smooth integration.<\/span><\/p>\n Add the following lines of code into your `.htaccess` file:<\/span><\/p>\n “`apache<\/span><\/em><\/p>\n <IfModule mod_headers.c><\/span><\/em><\/p>\n \u00a0\u00a0\u00a0\u00a0Header set Access-Control-Allow-Origin “*”<\/span><\/em><\/p>\n \u00a0\u00a0\u00a0\u00a0Header set Access-Control-Allow-Methods “GET, POST, OPTIONS, DELETE, PUT”<\/span><\/em><\/p>\n \u00a0\u00a0\u00a0\u00a0Header set Access-Control-Allow-Headers “Content-Type, Authorization”<\/span><\/em><\/p>\n <\/IfModule><\/span><\/em><\/p>\n “`<\/span><\/em><\/p>\n What This Does:<\/b><\/p>\n Access-Control-Allow-Origin “*” ` allows all domains to access your resources. Replace `*` with a specific domain (`https:\/\/example.com`) for more control.<\/span><\/p>\n Security Tip<\/b>: Avoid using `”*”` for production APIs unless you’re aware of the risks. It’s safer to specify only the domains you trust.<\/span><\/p>\n Click <\/span>Save Changes<\/b> in the editor, then close the file.<\/span><\/p>\n You can test if CORS is working properly by:<\/span><\/p>\n If the header appears correctly, your CORS configuration is now active.<\/span><\/p>\n -><\/span>Still not working?<\/b> Check if your server has Apache’s `mod_headers` module enabled.<\/span><\/p>\n ->U<\/span>sing a CMS like WordPress<\/a>?<\/b> Make sure caching plugins aren\u2019t interfering.<\/span><\/p>\n<\/p>\n
\u00a0Step-by-Step: How to Enable CORS in cPanel<\/span><\/h2>\n
\u00a0Prerequisites:<\/span><\/h3>\n
\n
Step 1: Log in to your cPanel<\/span><\/h3>\n
\n
\u00a0Step 2: Open File Manager<\/span><\/h3>\n
\n
\u00a0Step 3: Navigate to Your Website Root Directory<\/span><\/h3>\n
\n
\u00a0Step 4: Reveal Hidden Files<\/span><\/h3>\n
\n
\u00a0Step 5: Edit the .htaccess File<\/span><\/h3>\n
\n
\u00a0Step 6: Insert CORS Configuration<\/span><\/h3>\n
\n
\u00a0Step 7: Save and Close<\/span><\/h3>\n
\u00a0Step 8: Test If CORS Is Enabled<\/span><\/h3>\n
\n
\u00a0Troubleshooting Tips<\/span><\/h3>\n