3

I'm having trouble setting up a rewrite and hoping someone knows the answer.

This is the code that i'm currently using in .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /point/to/dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+/.*)$ https://domain.ext/point/to/dir/module/status.php?id=$1 [L,QSA]

The client is requesting domain.ext/point/to/dir/ from the server, which should be rewritten to https://domain.ext/point/to/dir/module/status.php.

It is possible that a query is added to the end of the /point/to/dir/ request, which should be appended to https://domain.ext/point/to/dir/module/status.php. The /point/to/dir/ is a non-existing location on the server.

No matter what I do, I keep getting internal server errors (incorrect .htaccess configuration/syntax) or 404's. Hope someone can help out.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
jexos
  • 33
  • 3
  • Welcome to SO, kudos for adding your efforts in your question. Regarding `It is possible that a query is added to the end of the /point/to/dir/ request, which should be appended to https://domain.ext/point/to/dir/module/status.php. The /point/to/dir/ is a non-existing location on the server.` please do mention which query string you want to add it in your URL? – RavinderSingh13 Jul 13 '21 at 08:24
  • My apologies. My knowledge is very limited. Anything can be added to /point/to/dir/? . Anything after the backward slash (dir/*) should be appended to php*. – jexos Jul 13 '21 at 08:27

1 Answers1

3

With your shown samples, have your htaccess Rules file in following manner. Make sure you change your path from point/to/dir to your actual path(DO NOT put / in front of it in rule else that wouldn't work).

This is assuming that your point/do/dir has module folder and index.php inside module folder too.

Make sure to clear your browser cache before testing your URLs.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /point/to/dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(point/to/dir)/(.*)/?$ https://domain.ext/$1/module/status.php?id=$2 [NC,L,QSA]


OR in case you are in same domain name then you need not to mention complete url in right part of rewriting, have it then following way, make sure either use above or following rules one at a time only.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /point/to/dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(point/to/dir)/(.*)/?$ $1/module/status.php?id=$2 [NC,L,QSA]
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93