Stuart Brian Stuart Brian - 1 year ago 176
Apache Configuration Question

Mod_rewrite not working on localhost Apache/2.4.17

I have been try to rewrite clen url in Apache/2.4.17 i use bellow code and is working fine online but does't work in localhost

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /my_website_dir/
#remove extention
RewriteRule ^([^/\.]+)/?$ $1.php [L,QSA]

RewriteCond %{THE_REQUEST} /userprofile\.php\?u=([^\s&]+) [NC]
RewriteRule ^ /userprofile/u/%1? [R=301,L]
RewriteRule ^userprofile/u/([^/]+)/?$ /userprofile.php?u=$1 [L]

Above code show this

Object not found!

The requested URL was not found on this server. If you entered the URL
manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.
Error 404 localhost Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.23

Now i also tried this only in localhost and it worked but not correctly

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /my_website_dir/
#remove extention
RewriteRule ^([^/\.]+)/?$ $1.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ userprofile.php?u=$1 [L]

Here is what i get
when i want to get the parameter value of u i get this
but i only need to return peter in
echo $_GET['u']

Answer Source

Change your last line with:

RewriteRule ^userprofile/u/([^/]+)/?$ userprofile.php?u=$1 [L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download