Home  >  Q&A  >  body text

Problem: Problem when using rewrite rules to redirect a folder to a PHP file with the same name

Directly have the root directory as shown below, as you can see I have a folder and file with the same name as store , you Can you please let me know how to write RewriteRule in .htaccess to redirect any request like

http://clients/shop/ or http://clients/shop

to

http://clients/shop.php

I already tried it

RewriteRule ^shop/(.+) shop.php [L,R]

But this adds the wrong address to the URL

======================

renew

====================

Okay, I found this solution works to some extent

DirectorySlash Off 
RewriteEngine on 
RewriteCond %{THE_REQUEST} \s/+shop [NC]

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)  /.php [R=302,L]

But, it only works when the request is like http://clients/shop, and it shows the directory page when the request is like http://clients/shop/

P粉787820396P粉787820396221 days ago520

reply all(1)I'll reply

  • P粉129275658

    P粉1292756582024-04-05 10:46:58

    This should do the job for you

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /shop [NC]
    RewriteRule ^shop - [R=404,L]
    
    RewriteRule ^shop/(.*)$ shop.php [L,NC]

    reply
    0
  • Cancelreply