apache2 - Mod Rewrite problems -
i having problems mod rewrite. server ubuntu 12.04, apache2, php 5.4.
i want url this:
www.website.com/<modelname>/<imagenumber>
and
www.website.com/<modelname>
to show:
www.website.com/showimage.php?model=<modelname>&image=<imagenumber>
and
www.website.com/model.php?model=<modelname>
i have put in .htaccess:
rewriteengine on rewriterule ^([^/]+)/([0-9]+)/?$ showimage.php?model=$1&image=$2 [r,l,nc,qsa] rewriterule ^([^/]+)/?$ model.php?model=$1 [r,l,nc,qsa]
i have checked mod_rewrite loaded in apache. page doesn't redirect.
edit: clarify, result 404 'the resource / not exist on server' , 'the resource // not exist on server'.
the strange thing playing around yesterday , tried make rule included website.com/model/modelname , seem in effect , impossible rid of. have tried restart apache ten times, clear browser caches , install browser didn't have before die-hard redirect yesterday keeps going in new browser (firefox).
are new redirect rules have written correct?
how put them in action?
should set chmod 777 on .htaccess?
thanks lot...
edit: here more information.
i have 1 (default) site , files (including .htaccess) sitting in /var/www
the file /etc/apache2/sites-available/default looks this:
<virtualhost *:80> serveradmin webmaster@localhost documentroot /var/www <directory /> options followsymlinks allowoverride </directory> <directory /var/www/> options indexes followsymlinks multiviews allowoverride none order allow,deny allow </directory> scriptalias /cgi-bin/ /usr/lib/cgi-bin/ <directory "/usr/lib/cgi-bin"> allowoverride none options +execcgi -multiviews +symlinksifownermatch order allow,deny allow </directory> errorlog ${apache_log_dir}/error.log # possible values include: debug, info, notice, warn, error, crit, # alert, emerg. loglevel warn customlog ${apache_log_dir}/access.log combined alias /doc/ "/usr/share/doc/" <directory "/usr/share/doc/"> options indexes multiviews followsymlinks allowoverride none order deny,allow deny allow 127.0.0.0/255.0.0.0 ::1/128 </directory>
i haven't changed there except directory / allowoverride all
.htaccess looks this:
rewriteengine on rewritelog "/etc/apache2/logs/rewrite.log" rewriteloglevel 9 rewritebase / rewriterule ^([^/]+)/([0-9]+)/?$ showimage.php?model=$1&image=$2 [r,l,nc,qsa] rewriterule ^([^/]+)/?$ model.php?model=$1 [r,l,nc,qsa]
and have run service apache2 restart endless times.
this url works fine:
/showimage.php?model=ai&image=12
this 1 doesn't:
/ai/12
help!
rewriteengine on rewriterule ^([^/]+)/([0-9]+)/?$ showimage.php?model=$1&image=$2 [r,l,nc,qsa] rewriterule ^([^/]+)/?$ model.php?model=$1 [r,l,nc,qsa]
rather going "this should work", i'll leave translating rules:
- the first rule match [anything]/[digits] or without trailing slash , re-map showimage.php?model=$1&image=$2 using redirect, break chain (i.e. second rule won't executed), case-insensitive (not needed), , preserves query string arguments. second same, model.php.
it important note second rule not match empty string (i.e. fetching /). might part of problem.
the rules correct. can test these on rewrite tool at: http://martinmelin.se/rewrite-rule-tester/ .
what believe problem is pretty simple. please answer following questions in comment , i'll advise there:
- are trying fetch / without index? if so, neither of rules matching , why you're getting 404.
- if not, exact url trying fetch? have access server logs? if so, can turn on rewrite log?
Comments
Post a Comment