0

I'm using URL Rewriting for a simple note application in my website. All things are UNDER /notes/ directory. .htaccess contents are,

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L]

and the url which is to be accessed is,

http://localhost/notes/test.txt

I want to get test.txt as the filename variable's value.

But when I use echo $_GET['filename']; in index.php, it displays index.php instead of displaying test.txt.

here, test.txt is not a real text file but the filename variable's value.

1
  • Did the answer fix your problem? Commented Sep 17, 2015 at 7:23

1 Answer 1

2

I think the problem is that your "index.php?filename=test.txt" URL is also being processed and rewritten by your rule. You might need to change your .htaccess code to stop references to files that exist being rewritten:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L]
Sign up to request clarification or add additional context in comments.

Comments

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.