How to redirect from new.php on new?
site.com/new.php
it doesn't look as nice as site.com/new
This rule doesn't want to work
RewriteRule ^new$ new.php [L,QSA]
UPD:
ErrorDocument 404 http://site.com/error.php
RewriteEngine On
RewriteRule ^new new.php [L,QSA]
RewriteCond %{REQUEST_URI} ^/page/1$
RewriteRule ^.*$ http://site.com/? [R=301,L]
RewriteCond %{REQUEST_URI} ^/app/page/1$
RewriteRule ^.*$ http://site.com/app? [R=301,L]
RewriteCond %{REQUEST_URI} ^/game/page/1$
RewriteRule ^.*$ http://site.com/game? [R=301,L]
RewriteRule ^(.*)$ error.php [L,QSA]
1 answers
As the TS pointed out, site.com/new
outputs to page 404. If the rule works, and new
is redirected to new.php
, the simplest possible reason is the absence of the new.php
file itself.
Then, as @alexander barakin correctly suggested, the terminating $
was "lost" in the rule, resulting in not only site.com/new
, but also site.com/newwhatever
resulting in new.php
.
Update: according to this article, if the address changes after applying the ruleset, then the rules are run again (possibly, in the new directory) as long as there are changes.
Given that the last rule in the list replaces everything with an error page, this could lead to a problem. In this case, the first run will replace new
with new.php
, but during the second run, only the last rule will work, and will replace new.php
with error.php
.
Thus, it may be necessary after the rule
RewriteRule ^new$ new.php [L,QSA]
Add
RewriteCond %{REQUEST_URI} ^/new$
RewriteRule ^new.php$ new.php [L,QSA]
This rule will fire a second time, finish processing the rules ([L]
), and won't let the final rule work. RewriteCond
it is necessary that the rule does not work on the new.php
entered in the browser.