Home > front end >  Point folder root URL to file using .htaccess
Point folder root URL to file using .htaccess

Time:08-29

In my document root I have a subfolder link such that domain.com/link/something points to domain.com/link/default.php?id=something

In my .htaccess file (located in the subfolder link), I have the following:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT} !-f
RewriteRule ^(. )$ /default.php?id=$1 [L,QSA]

Unfortunately, it doesn't seem to work as domain.com/link/something gives a 404 error. Any tips?

CodePudding user response:

With your shown samples please try following .htaccess rules file.

Make sure:

  • Keep your .htaccess rules file, default.php files along with your link folder.
  • clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /link/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ default.php?id=$1 [QSA,L]
  • Related