Quantcast
Channel: How to remove php extension from pages except search results? - Webmasters Stack Exchange
Viewing all articles
Browse latest Browse all 2

Answer by MrWhite for How to remove php extension from pages except search results?

$
0
0
# To externally redirect /dir/foo.php to /dir/fooRewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]RewriteRule ^ %1 [R,L]

To exclude your "search" page from the redirect you could include an additional condition. Only redirect when the requested URL is not "search.php".

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s[^.]+\.phpRewriteCond %{REQUEST_URI} !search\.phpRewriteRule ^(.*)\.php$ $1 [R=301,L]

I've tweaked the rules a bit to make them more efficient by specifically checking for the ".php" file extension in the RewriteRule. Removed the NC flag as this seems redundant. Changed from R (temporary) to R=301 (permanent) redirect - I presume this should be "permanent"? (Although it's good to test with a temporary - non-cached - redirect.)

However, why the "search" page doesn't work without the file extension would seem to be another issue. It should work! There seems to be another (301) redirect that is redirecting /search?s=world to /search/?s=world?

You also still need to resolve all your internal linking so that you link to URLs without the .php extension otherwise your site is going to be issuing a lot of unnecessary redirects.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>