.htaccess - Mod_rewrite for single.php -
i'd use mod_rewrite show pretty urls in urls:
instead of .../juegos/plants-vs-zombies/?play=jugar change .../juegos/plants-vs-zombies/jugar/
and .../juegos/ddtank/?play=full change .../juegos/ddtank/full/
i use file "single.php" code:
$url = (isset($_server['https']) ? "https" : "http") . "://$_server[http_host]$_server[request_uri]"; $parts = parse_url($url); parse_str($parts['query'], $query); $parametro = $query['play']; if ($parametro == 'jugar') { include( get_template_directory() . '/single-play.php'); } else if ($parametro == 'full') { include( get_template_directory() . '/single-full.php'); }
and in .htaccess have this:
rewriteengine on rewritecond %{query_string} (^|&)play=jugar($|&) rewriterule ^(.*)/$ /jugar/?&%{query_string}
but when try url /jugar/ , /full/ @ end of url, displays 404 error.
i don't know else do. hope can me.
sounds pretty straight forward me:
rewriteengine on rewriterule ^/?juegos/plants-vs-zombies/jugar/?$ /juegos/plants-vs-zombies/?play=1 [end]
for work rewriting module has installed , enabled, obviously. rule work likewise in http servers host configuration , in dynamic configuration file (.htaccess
). if decide use dynamic configuration file, need place in http hosts document root folder , enable interpretation using allowoverride
directive in host configuration.
if receive http status 500 using above rule ("server internal error") chances operate old version of apache http server. in case try replacing [end]
flag [l]
flag.
and general hint: should prefer place such rules inside http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess
style files). files notoriously error prone, hard debug , slow down server. supported last option situations not have control on host configuration (read: cheap hosting service providers) or if have application relies on writing own rewrite rules (which obvious security nightmare).
Comments
Post a Comment