clemente Posted November 26, 2019 Share Posted November 26, 2019 I have written a rule that if a file doesn't exist, then look for it in "sub1" folder, for example: when someone goes to www.example.com/file15 it will rewrite to -> www.example.com/sub1/file15, and it works RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ sub1/$1 [QSA] But there are more folders than sub1, so if a "file15" doesn't exist in sub1, then look for it in folder sub2, and if it's not in sub2, then rewrite to sub3. I tried this but doesn't work: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ sub1/$1 [QSA] RewriteCond sub1/%{REQUEST_FILENAME} !-f RewriteCond sub1/%{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ sub2/$1 [QSA] Quote Link to comment Share on other sites More sharing options...
requinix Posted November 26, 2019 Share Posted November 26, 2019 This isn't good. Why do you have so many subdirectories? Why are you not using the correct URL? Quote Link to comment Share on other sites More sharing options...
clemente Posted November 26, 2019 Author Share Posted November 26, 2019 (edited) There is only few subdirectories, I want URL to be shorter. Edited November 26, 2019 by clemente Quote Link to comment Share on other sites More sharing options...
clemente Posted November 26, 2019 Author Share Posted November 26, 2019 Okay will just stick to /sub/ folders, can close this Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 26, 2019 Share Posted November 26, 2019 8 hours ago, clemente said: I want URL to be shorter It may be beyond your skills, but If that is the goal you can write a router that will call whatever file you want regardless of the name and URL. Look into MVC design. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 26, 2019 Share Posted November 26, 2019 10 hours ago, clemente said: There is only few subdirectories, I want URL to be shorter. Then don't put the files into subdirectories. What I'm trying to understand is why you want everything to look and act a certain way but weren't making it actually be that way. Quote Link to comment Share on other sites More sharing options...
clemente Posted November 26, 2019 Author Share Posted November 26, 2019 There are subdirectories because there are different categories, they need to be seperated for automating things, just without the /sub1/ URL looks nicer. Figured it out, this did the job: RewriteCond %{DOCUMENT_ROOT}/sub1/%{REQUEST_URI}/index.php -f RewriteRule ^(.*)$ sub1/$1 [L] RewriteCond %{DOCUMENT_ROOT}/sub2/%{REQUEST_URI}/index.php -f RewriteRule ^(.*)$ sub2/$1 [L] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.