@emelie
To redirect invalid URLs using .htaccess, you can use the following codes:
1
2
3
4
|
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L,R=301]
|
Here's a breakdown of what each line does:
- RewriteEngine On: Enables the Apache mod_rewrite module.
- RewriteCond %{REQUEST_FILENAME} !-f: This line checks if the requested URL does not point to an existing file.
- RewriteCond %{REQUEST_FILENAME} !-d: This line checks if the requested URL does not point to an existing directory.
- RewriteRule ^(.*)$ /index.php [L,R=301]: This line redirects any invalid URL to "/index.php" with a 301 (permanent) redirect status.
Replace "/index.php" with the desired URL to redirect invalid URLs to.