How do I convert a PHP query string into a slash-based URL?

Simple .htaccess example: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^lookup/([a-z0-9\-]+)/item/?$ /lookup.php?id=$1 </IfModule> This will match any alphanumeric (also will recognise dashes) string of any length as the ‘id’. You can limit this to just numeric by changing the regex to ([0-9]+). <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^lookup/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ /lookup.php?id=$1&view=$2 </IfModule> This one will match /lookup/123/some-text/ to /lookup.php?id=123&view=some-text

Routing URLs in PHP

Use mod_rewrite to route everything to a single index.php file. Then check the variable in $_SERVER[‘REQUEST_URI’] within this file to dispatch to the required handler. This configuration will enable mod_rewrite, if it’s installed: DirectorySlash Off Options FollowSymLinks Indexes DirectoryIndex index.php RewriteEngine on RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ – [L] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^.*$ – … Read more

how to enable shell_exec and exec on php?

If you are not the root on the machine, and exec() function is disabled, then you can’t enable it by yourself. See http://php.net/manual/en/ini.core.php#ini.disable-functions disable_functions string This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode. Only internal functions … Read more

.htaccess Redirect non-WWW to WWW preserving URI string

I had a similar problem, and this .htaccess works for me RewriteEngine On #This bit rewrites your host name to include www RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L] #This bit does the codeigniter magic RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L]

Apache mod_rewrite REDIRECT_STATUS condition causing directory listing

You have this condition to stop looping: ## Internal Redirect Loop Protection RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule ^ – [L] This works by checking internal Apache variable %{ENV:REDIRECT_STATUS}. This variable is empty at the start of rewrite module but is set to 200 when first successful internal rewrite happens. This above condition says bail out of … Read more

htaccess RewriteRule page with query string

You need to match against the %{QUERY_STRING} variable. The query string isn’t part of the match in a RewriteRule: RewriteCond %{QUERY_STRING} ^who=a$ RewriteRule ^people.php$ /people/?t=leadership [R=301,L] RewriteCond %{QUERY_STRING} ^who=f$ RewriteRule ^people.php$ /people/?t=faculty [R=301,L] RewriteCond %{QUERY_STRING} ^who=p$ RewriteRule ^people.php$ /people/?t=students [R=301,L] RewriteCond %{QUERY_STRING} ^who=r$ RewriteRule ^people.php$ /people/ [R=301,L] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^people.php$ /people/ [R=301,L]