0

I have the following code in my .htaccess file, placed in the root of my Ubuntu 22.04 instance:

Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^profile/([^/]*)$ /profile.php?user=$1 [L] 

My goal is to use:

example.com/profile/johndoe

to get the following output URL:

example.com/profile.php?user=johndoe

but it doesn't work :(

mod_rewrite is on

My apache2.conf looks like this:

<Directory /> Options FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> 

I don't know what I'm doing wrong, any help will be greatly appreciated

1 Answer 1

1

You can try putting your .htaccess file in /var/www/html/. Your issue is probably permission related. Check your logs in /var/log/apache2/access.log and /var/log/apache2/error.log for more details.

Also, do not allow access to the root filesystem, it's a security issue. So change

<Directory /> Options FollowSymLinks AllowOverride All Require all granted </Directory> 

to

<Directory /> Options FollowSymLinks Require all denied </Directory> 
1
  • Thanks, my htaccess file is already in var/www/html/, I’ll check access.log to see if there’s anything wrong, anyway if I perform a rewrite rule on the index.php, it works, it just doesn’t get another php file with a single?parameter :( Commented Sep 6, 2023 at 17:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.