1
RewriteEngine on RewriteCond %{REQUEST_URI} !(\.|/$) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ api.php?url=$1 [L] 

Above shows my current configuration.

The problem with this is it only seems to be redirecting if a directory or file exists after the folder the htaccess file is in.

How can I rewrite this so it literally just redirects every single request to api.php with the full requested path? I'm not looking to see whether directories or files exist in the htaccess file, I can do that in api.php, I just want to push all the requests through that file.

2 Answers 2

1

You can use:

RewriteEngine on RewriteCond %{REQUEST_URI} !(\.|/$) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] RewriteRule ^((?!api\.php$).*)$ api.php?url=$1 [L,QSA,NC] 

Lookahead (?!api\.php$) means rewrite everything except /api.php to /api.php with query parameter url.

Sign up to request clarification or add additional context in comments.

Comments

0

like this:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^?]*)$ /api.php?path=$1 [NC,L,QSA] 

make sure you have this before the route

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.