apache - Clean URLS www. to non, remove index.php, remove .php extention, add trailing slash using HTACCESS -
so seems can find solutions of these can't them work together. trying create clean urls sides.
resolve www. , non-www. non www. page remove occurrences of index.php (i.e. if navigating folder /blog/index.php resolve /blog/) remove php extension urls (i.e. /page.php /page/) add trailing slash (i.e. /page /page/)this have far:
rewriteengine on rewritecond %{request_filename} !-f rewriterule .*[^/]$ %{request_uri}/ [l,r=301] rewritecond %{request_filename}.php -f rewriterule ^(.+)/$ $1.php [l] this accomplishes clean url's removing .php extension , adding trailing slash. had take out www.to non , removal of index.php because clean urls , trailing slashes stopped working. give thanks in advance.
here's .htaccess should like:
rewriteengine on # remove www. <ifmodule mod_rewrite.c> rewritecond %{https} !=on rewritecond %{http_host} ^www\.(.+)$ [nc] rewriterule ^ http://%1%{request_uri} [r=301,l] </ifmodule> # remove file extensions, add together trailing slash. rewritecond %{request_filename} !-f rewriterule ^([^/]+)/$ $1.php rewriterule ^([^/]+)/([^/]+)/$ /$1/$2.php rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewritecond %{request_uri} !(\.[a-za-z0-9]{1,5}|/)$ rewriterule (.*)$ /$1/ [r=301,l] this reference article removing file extensions fro urls. remember, work, must reference non-extension version in of links e.g. <a href="about">about</a>, not <a href="about.php">about</a>
while you're doing .htaccess things, might recommend adding in next snippets. first 2 concerned website speed, sec custom 404 page, , 3rd forcing utf-8 (so don't have declare in html).
# expires caching (caching static files longer drastically improves performance, might want set more aggressive times) <ifmodule mod_expires.c> expiresactive on expiresbytype image/jpg "access 1 year" expiresbytype image/jpeg "access 1 year" expiresbytype image/gif "access 1 year" expiresbytype image/png "access 1 year" expiresbytype text/css "access 1 month" expiresbytype text/html "access 1 month" expiresbytype text/x-javascript "access 1 month" expiresbytype image/x-icon "access 1 year" expiresdefault "access 1 month" </ifmodule> # gzip <ifmodule mod_deflate.c> addoutputfilterbytype deflate text/text text/html text/plain text/xml text/css application/x-javascript application/javascript </ifmodule> # 404 page errordocument 404 /404.php # forcefulness utf-8 adddefaultcharset utf-8 i wrote this in blog post on codepen, if you're interested.
html bp has insane 700+ line .htaccess can see cool tricks.
php apache .htaccess mod-rewrite
No comments:
Post a Comment