Development and databases
Set up friendly URLs and mod_rewrite rules
mod_rewrite rules let you route a URL to another resource or return a redirect to the browser. At Hostsuar, LiteSpeed interprets Apache-compatible rules. The application decides which routes it needs and how they should be resolved.
Rewrite and redirect
An internal rewrite can serve index.php when you visit /productos, keeping that URL in the browser. An HTTP redirect returns a destination and the browser requests another address. They are not interchangeable: adding a redirect does not configure a CMS's internal routes.
This line enables rule processing in the relevant context:
RewriteEngine On
On its own it does not create friendly URLs. It needs the application's specific rules.
Apply the project's rules
- Confirm the domain's document root and keep a private copy of the existing
.htaccess. - Get the rules from the application's documentation for your type of installation, including whether it is in a subfolder or is a multisite.
- If it provides a file such as
htaccess.txt, review its content before renaming it. If.htaccessalready exists, also keep the rules the hosting or the rest of the site needs. - Turn on the application's friendly URLs or permalinks option where applicable.
- Test an internal page, a static file and an address that does not exist.
In WordPress, Settings > Permalinks can regenerate its rules if it has permission to write the file; otherwise it shows instructions for applying them. Do not replace a multisite network's rules with those of a single installation.
Check the result
- If the home page works but internal pages return 404, check where the rules are, the domain's document root and the application's route settings.
- If there is a loop, check the HTTPS,
wwwand subfolder rules and the redirects set up in the application or the proxy. - If a 500 appears, revert the change and check the log: there may be incorrect syntax or a directive that is not allowed.
In .htaccess, the RewriteRule pattern is evaluated relative to that directory and does not normally start with /. A rule copied from the server's main configuration may need adapting. See the official introduction to mod_rewrite when you write your own rules.
Keep old URLs that are still in use and set up redirects to their equivalent if you change the structure. Avoid sending them all to the home page: each destination should match the content the visitor was looking for.
You may also find useful
- The .htaccess file, what you need to know Learn how .htaccess applies recursively and which options it lets you adjust per directory; errors,...
- Apache handlers Set from cPanel which Apache handler should process a given extension, and learn why this option cal...
- Available binaries and tools - FFmpeg, Tesseract, ImageMagick, cURL and more See which binaries are available for video, images, PDF, OCR, networking, DNS, version control and o...
- Create and run cron jobs in cPanel Set up cron jobs in cPanel, define intervals and commands, manage notifications, call URLs with cURL...
Something wrong or out of date? Tell us and we will review it.