I am trying to get Apache 2.2 mod_rewrite to get clean urls.
I have links such as
<ul>
<li><a href="index.php?view=pageName">Page Name</a></li>
<li><a href="index.php?view=pageName2">Page Name2</a></li>
<li><a href="index.php?view=pageName3">Page Name3</a></li>
</ul>
and url comes out to be
http://example.com/user/index.php?view=pageName
I would like to clean the url in the address bar it to this
http://example.com/user/pageName
Edit: This is what’s in my httpd.conf if it’s any use.
<Directory "C:/Apache2.2/htdocs/user">
Options Indexes FollowSymLinks
AllowOverride all
order allow,deny
Allow from all
</Directory>
Using phpinfo() I have verified that mod_rewrite is loaded and I have this in my .htaccess (user file, Not root .htaccess) and not virtual user on apache
RewriteEngine on
RewriteBase /user/ #Edited rewrite base added in, but not helping much.
RewriteOptions Inherit
RewriteRule ^/user/([a-zA-Z])/?$ index.php?view=$1 [NC,L]
Edit: the rest of my .htaccess
#Ensure browser reads Header
Header unset ETag
FileETag None
Header unset Last-Modified
#Set caching expires
Header set Expires On
ExpiresDefault "access plus 30 days"
#gzip
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
does not work the same on all menu links which are identical in html structure, and not working properly. IE: It sends me to http://example.com/user/?view=pageName, but is loading the root HTML file content.
If I change this line
RewriteRule ^/user/([a-zA-Z])/?$ index.php?view=$1 [NC,L]
to
RewriteRule ^index\.php$ http://www.google.com [NC,L]
I get sent to google as expected. So obviously I must be doing something wrong with the matching and replacing, but what am I doing wrong?
Thanks in advance.
Edit:
access.log and error.log are error free.
Fixed: Had to change HTML URL style to be used as such
Then in
.htaccessAlso had to disable mod_cache.so from apache’s httpd.conf as it interfere with rewrite if there are any caches left behind. Hope this helps others to get clean urls working.