htaccess - remove index.php and keep a variable without key htaccess - remove index.php and keep a variable without key apache apache

htaccess - remove index.php and keep a variable without key


You may use these rules in your site root .htaccess:

DirectoryIndex index.phpRewriteEngine On# remove index.phpRewriteCond %{THE_REQUEST} /index\.php\s [NC]RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]RewriteRule ^ %1 [L,R=301,NE]# external redirect from actual URL to pretty oneRewriteCond %{THE_REQUEST} \s/+index\.php\?c=([^\s&]+) [NC]RewriteRule ^ /%1? [R=301,L,NE]# internal forward from pretty URL to actual oneRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^/.]+)/?$ index.php?c=$1 [L,QSA]


Could you please try following, based on your shown samples.Please do clear your browser cache before testing your URLs.

RewriteEngine ON##This rule is for handling index.php file in uri.RewriteCond %{QUERY_STRING} ^$RewriteRule ^index\.php/?$ / [R=301,NC,L]   ##This rule is to redirect from index.php?c=lorem to lorem in uri.RewriteCond %{THE_REQUEST} index\.php\?c=(lorem)\s [NC]RewriteRule ^ http://%{HTTP_HOST}/%1? [R=301,L,NE]##Rule for non-existing files/directories to index.php with variables.RewriteCond  %{REQUEST_FILENAME} !-fRewriteCond  %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?c=$1 [L]


OR: Above is for specifically lorem in case your query string could be anything then try following.

RewriteEngine ON##This rule is for handling index.php file in uri.RewriteCond %{QUERY_STRING} ^$RewriteRule ^index\.php/?$ / [R=301,NC,L]   ##This rule is to redirect from index.php?c=lorem to lorem in uri.RewriteCond %{THE_REQUEST} index\.php\?c=([^\s&]*) [NC]RewriteRule ^ http://%{HTTP_HOST}/%1? [R=301,L,NE]##Rule for non-existing files/directories to index.php with variables.RewriteCond  %{REQUEST_FILENAME} !-fRewriteCond  %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php?c=$1 [L]