.htaccess redirect with forward slash

Viewed 30

My index.php file is inside s directory like

https://example.com/s/index.php

I have .htaccess file like below

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?random=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?random=$1&java=$2 [L]

its working fine and redirecting properly

like https://example.com/s/15091722/yes

But I want add one more variable like

https://example.com/s/15091722/yes/152030

so I have tried like

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?random=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?random=$1&java=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?random=$1&java=$2&u=$3 [L]

But its giving me error called not found. I think I am missing something but not getting idea. Let me know if anyone here can help me for the same.

Thanks!

1 Answers

Your first example doesn't work for me at all, see https://htaccess.madewithlove.com?share=d6d58756-3171-4ace-99d3-354694f52b24. Your path consists of three segments (s, 15091722 and yes). But in your rule you only asking for one or two of them to match.

What you basically need to do is to extend your rule by more path segments eg: https://htaccess.madewithlove.com?share=edd7cb32-be87-49ac-ac72-562922bd2a49

As you may notice, splitting paths like that could get messi very soon. So maybe it should be worth it thinking about redirecting everything to index.php and splitting path segments dynamically with your programming language afterwords

Related