1

I want ajax/file address to be redirected to ajax/file.php using .htaccess. I created a .htaccess file like below but that gives a 500 Internal Server Error.

RewriteEngine On
RewriteRule ^ajax/(.*)$ ajax/$1.php [L]

An additional information is that my website is working under a sub-folder. (localhost/myproject) RewriteRule ^ajax/(.*)$ /ajax/$1.php [L] redirects url to (localhost/ajax/file.php) instead of (localhost/myproject/ajax/file.php

1 Answer 1

1

Problem is that .* in your regex also matches file.php.

Use your rule like this:

Options -MultiViews
RewriteEngine On

RewriteRule ^ajax/([^./]+)/?$ ajax/$1.php [L]
Sign up to request clarification or add additional context in comments.

1 Comment

and [^./]+ supposed to be select file only in file.php. Thank you it works very well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.