Critical
Critical

Reputation: 45

.htaccess rewriting not working

My current url: http://website.com/user.php?user=jon What I want it to look like: http://website.com/jon

This is what I currently have in my htaccess file

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST-FILENAME} !-d
RewriteCond %{REQUEST-FILENAME} !-f
RewriteCond %{REQUEST-FILENAME} !-l

RewriteRule . user.php?user=%{REQUEST-FILENAME}

But it does not work.

Upvotes: 1

Views: 51

Answers (2)

Brett
Brett

Reputation: 2010

You need to change your - to _ - it is REQUEST_FILENAME not REQUEST-FILENAME

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule . user.php?user=%{REQUEST_FILENAME}

I prefer to use the regex part of the rule

RewriteRule ^(.*)$ user.php?user=$1 [NC,L]

Upvotes: 2

James Lockhart
James Lockhart

Reputation: 1040

Do you have AllowOverride enabled for that directory in your virtual hosts or Apache config?

e.g.

<Directory "/">
    AllowOverride All
</Directory>

If not then your local htaccess file will be ignored. Also, do you have mod_rewrite enabled?

If unsure check your Apache log files.

https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

Upvotes: 2

Related Questions