0

I am stuck with a mod rewriting on Apache htaccess.

my URL looks like this :

http://localhost/Ac5GRnXW

I want it to redirect like this:

http://localhost/redirect.php?id=Ac5GRnXW

I am using the following code :

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(\w+)$ ./redirect.php?id=$1

Please help

11
  • The script you've posted should already do as you require (although you should remove the ./ prefix from the substitution string). Have you enabled .htaccess overrides in the server config? (.htaccess files are an optional extra - they are not processed by default.)
    – MrWhite
    Commented Oct 31, 2022 at 12:49
  • yes htaccess is configured in httpd conf file and removing ./ prefix wont help
    – Anjali
    Commented Oct 31, 2022 at 15:17
  • So what happens exactly? Are you getting an error? Undesirable response? Nothing? Where are the .htaccess and redirect.php files located? Do you have any other directives in the .htaccess file? How is your server configured? Try writing some "nonsense" at the top of the .htaccess file - do you get an error?
    – MrWhite
    Commented Oct 31, 2022 at 16:02
  • all files located in root directory. I am getting 404 error URL not found when trying to access localhost/Ac5GRnXW. I don't have any other directive in htaccess file. writing some nonsense at top of it gives 500 error for internal server.
    – Anjali
    Commented Oct 31, 2022 at 16:46
  • To clarify, requesting /redirect.php?id=Ac5GRnXW directly works as intended? Try (temporarily) changing the rewrite into an external redirect, ie. RewriteRule ^(\w+)$ /redirect.php?id=$1 [R,L] (note that the subst string starts with a slash in this instance). What happens? Are you redirected?
    – MrWhite
    Commented Oct 31, 2022 at 17:18

0

You must log in to answer this question.

Browse other questions tagged .