php - .htacces url_rewrite difficulties -
i have problem configuration of .htaccess
of small website i'm working on.
i want pages redirected index.php?page=request
, file find in database content requested page.
the problem occurs when have installed forum, want these forum pages redirect index.php?page=forum¶ms
options +followsymlinks rewriteengine on rewritecond %{request_uri} /(.*).html rewriterule ^(.*)forum/category/(.*)?$ index\.php?page=forum&lang=$1&category=$2 [l] rewriterule ^(.*)/(.*)(\.html?)$ index\.php?lang=$1&page=$2 [l] rewriterule ^(.*)(\.html?)$ index\.php?page=$1 [l]
evetything works fine, except forum part. how need change .htacces
?
the problem appears rewritecond
matching requests end in .html
. forum urls don't end in .html
condition subsequent rewriterule never met.
there other possible problems too:
^(.*)forum
matchwww.url.com/en/
when looks wanten
category/(.*)
match characters, including forward slashes , like. presumably want match decimal identifier.links things aren't covered rewrite config e.g. images
i'd rewrite config (n.b. not tested in apache; in regex debugger):
rewriteengine on # match forum urls # e.g url.com/en/forum/category/12345 rewritecond %{request_uri} ^/.+/forum/category/[0-9]+ rewriterule ^/(.+)/forum/category/([0-9]+) index.php?page=forum&lang=$1&category=$2 [l] # match urls ending in .html # e.g. url.com/en/foo.html # , url.com/foo.html rewritecond %{request_uri} ^/.+\.html$ # bit complicated, matches both # /apage.html # /folder/apage.html rewriterule ^(?:/(.+))?/(.+)\.html$ index.php?lang=$1&page=$2 [l]
the second rewriterule should provide value page
provide value lang
if url of form /lang/page.html. should ok if index.php file can accept empty lang
parameter or supply default value.
alternatively, if don't mind keeping existing regex , it's images, css etc want bypass in url rewriting can add rules @ start skip them e.g.
rewriteengine on # don't rewrite, , stop processing rules rewriterule \.(jpg|png|css|js)$ - [l] # match forum urls # e.g url.com/en/forum/category/12345 rewritecond %{request_uri} ^/.+/forum/category/[0-9]+ rewriterule ^/(.+)/forum/category/([0-9]+) index.php?page=forum&lang=$1&category=$2 [l] etc...
Comments
Post a Comment