I want to rewrite /home to the index.php and /edit to edit.php, but everything else, like /asdfg I want to redirect to new.php
Both edit and home on their own work, but the (.*) takes priority over those rules, I tried it without the RewriteCond, but then nothing works.
RewriteEngine on
RewriteBase /
RewriteRule ^home$ /index.php
RewriteRule ^edit$ /edit.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /new.php [L,R=301]
I just need all undefined URI’s to redirect to /new.php
I also need to keep the /asdfg in the URI, so I can grab it with JavaScript and show the appropriate content, an either show a page to let ppl make a new post or to show existing content.
I can’t define all existing content, because that comes from a database, only a few predefined, reserved "/folders" will redirect to predefined pages.
I have the following working:
RewriteEngine on
RewriteRule ^home$ /index.php [R]
RewriteRule ^edit$ /edit.php [R]
It leaves the /home there and go to index.php
Now I just need to redirect all unknown requests to a default page new.php.
I basically want to prevent users getting a 404 or any other error, ever..
You need to add the
lastflag to your first RewriteRules, so that the last RewriteRule does not take effect: