2

Have file create.php

Want if user types domain.com/create.php show domain.com/create

in .htaccess above RewriteEngine on placed this

RewriteRule ^create/?$ create.php [NC]

But if i type domain.com/create.php, i see .php

how to allow access to create.php file only from url domain.com/create?

1 Answer 1

3

You can use this code in your DOCUMENT_ROOT/.htaccess file:

Options -MultiViews
RewriteEngine On
RewriteBase /

# To externally redirect create.php to create
RewriteCond %{THE_REQUEST} \s/+(create)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]

# To internally forward create to create.php
RewriteRule ^(create)/?$ $1.php [L,NC]
Sign up to request clarification or add additional context in comments.

8 Comments

I see the loop. But I thought [R=302,L] and [L] alone should prevent this problem. Thanks again !
On server works, but on local computer with wamp does not work. OK, seems something wrong with my local computer (create.php is not in root).
Yes this rule will work when create.php is in DocumentRoot. Otherwise RewriteBase and RewriteCond %{THE_REQUEST} \s/+(create)\.php[\s?] [NC] lines need to be changed.
If create.php is in subfolder, then changed to RewriteBase /subfolder/ and RewriteCond %{THE_REQUEST} \s/+(subfolder/create)\.php[\s?] [NC] Yes, seems works. Just question regarding R=302. I changed to R=301 and it works. I "moved" create.php to create permanently (not temporary)
i have same problem but now working thanks anubhava
|

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.