To rewrite /$var/ into /$var.php and then redirect /$var.php into /$var/ just use these directives in your .htaccess file:
# once per htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-_]+)/? /$1.php
RewriteRule ^([a-z0-9-_]+).php$ /$1/ [R]
And if you also want to rewrite the specific URL /shops/shopName1/ into the specific URL /shopName1.php and then redirect /shopName1.php into /shops/shopName1/ then you should use this code below instead the code above:
# once per htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-_]+)/?$ /$1.php
RewriteCond %{REQUEST_URI} !^/shopName1.php$
RewriteRule ^([a-z0-9-_]+).php$ /$1/ [R]
RewriteRule ^shops/shopName1/?$ /shopName1.php
RewriteRule ^shopName1.php$ /shops/shopName1/ [R]
But remember there's no variable on /shops/shopName1/, give it a try, if you want..
It seems there's a problem about redirection with DirectoryIndex home.php
. But I think, this is the code that you want, but in this time, we excluded any redirection:
DirectoryIndex /home.php
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/shopName1/?$
RewriteCond %{REQUEST_URI} !^/shopName2/?$
RewriteCond %{REQUEST_URI} !^/shopName3/?$
RewriteCond %{REQUEST_URI} !^/shopName4/?$
RewriteCond %{REQUEST_URI} !^/shopName5/?$
RewriteRule ^([a-zA-Z0-9-_]+)/?$ /$1.php
RewriteRule ^shops/shopName1/?$ /shopName1.php
RewriteRule ^shops/shopName2/?$ /shopName2.php
RewriteRule ^shops/shopName3/?$ /shopName3.php
RewriteRule ^shops/shopName4/?$ /shopName4.php
RewriteRule ^shops/shopName5/?$ /shopName5.php
Just use your logic to add more conditions and rules..