url rewriting - Apache Mod rewrite help -



url rewriting - Apache Mod rewrite help -

i've been working on solution several hours & figured if doesn't mind helping me out, might save me time. question regards apache mod_rewrite; of course of study there tons of documentation out there, nil specific requirements are:

to take url in format:

language/pagename.php

(language either 'english' or 'french', write separate rule each. [only need illustration 1 though]. page name word character (w+). urls have .php extension).

and rewrite url doesn't alter in users browser, php receive in format:

language/page.php?slug=pagename

e.g. $_get['slug'] homecoming value pagename, , requests handled page.php.

so far best guess is

rewriteengine on rewritebase / rewriterule ^english/(\w+).php$ english/page.php?slug=$1

however create php tell me slug=page url illustration english/financial.php; rather financial.

have tried bunch of other regex conventions (.) instead of w & on..

use these rules:

rewriteengine on rewritebase / rewritecond %{request_filename} !-f rewriterule ^(english|french)/([^/\.]+)\.php$ /$1/page.php?slug=$2 [nc,qsa,l]

this needs place in .htaccess file in root folder. if placing config file (e.g. httpd-vhost.conf, within <virtualhost> directive), rule needs altered.

this rule should work language, long add together rule (english|french part).

this rule has status not rewrite if such file exists. this should solve problem slug=page: in rule have rewrite loop (after rewrite occurs goes next iteration -- that's how mod_rewrite works, , need have logic in place break loop). instead of rewritecond %{request_filename} !-f utilize rewritecond %{request_uri} !^/(english|french)/page\.php [nc] bit more hard maintain (you need add together languages here in rewrite rule itself).

if have other rewrite rules take care placing these in right place (order of rules matters).

because not know sure page names (slugs) be, i've used pattern: [^/\.]+ (any characters except / or .) .. may alter \w+ or whatever think better.

rule preserve optional page parameters (query string) -- useful preserving referrals/tracking code etc.

mod-rewrite url-rewriting

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -