I’m struggling with URL management when moving WordPress sites from my development environment to production. Every time I migrate, I have to manually update all the links which is really time consuming.
Current Setup:
My local XAMPP setup puts each WordPress installation in its own folder. Right now my root-relative paths include the project folder name:
/my-project/wp-content/themes/custom-theme/assets/js/main-script.js
/my-project/wp-content/uploads/2023/05/header-image.png
What I Want:
I need these URLs to work without the project folder prefix:
/wp-content/uploads/2023/05/header-image.png
/wp-content/themes/custom-theme/assets/js/main-script.js
What I’ve Tried:
- Created a custom local domain (mysite.local) and updated my hosts file
- Modified Apache virtual host settings
- Both approaches still require the subfolder in the URL structure
Is there a way to configure my local server so WordPress recognizes clean root-relative paths without the project directory name? This would make deployment much smoother.
you could also try local by flywheel instead of xampp. it handles domain mapping automatically - no need to fiddle with virtual hosts. much easier than setting up apache manually, and you get clean urls right away.
Had this problem for years until I found WP-CLI’s search-replace command. Skip the server config headaches - just run wp search-replace 'http://localhost/my-project' 'https://mysite.com' when you deploy. Takes 30 seconds and fixes all database URLs automatically. I stick with subfolders for dev since managing multiple projects is way easier. The key is automating URL replacement instead of trying to mirror production locally. Throw it in a deployment script and it’ll run every time you push changes.
You need to tweak your XAMPP’s Apache virtual host config. Change the DocumentRoot to point directly at your WordPress folder instead of the general htdocs directory. So instead of C:/xampp/htdocs, make it C:/xampp/htdocs/my-project. This’ll get rid of the project folder from your URLs. Restart Apache after you make the change. Apache will then treat your WordPress install as the root, so your local URLs match what you’ll have in production.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.