apache - Remove .php and add trailing slash in url using htaccess not loading css -


i have add following code htaccess file removing .php extension , add trailing slash urls. worked fine reduced page loading speed , css code not loading @ all. pages ugly.

please help

rewriteengine on rewritebase /  ## hide .php extension snippet  # externally redirect /dir/foo.php /dir/foo rewritecond %{the_request} ^[a-z]{3,}\s([^.]+)\.php [nc] rewriterule ^ %1/ [r,l]  # add trailing slash     rewritecond %{request_filename} !-f rewritecond %{request_uri} !/$ rewriterule . %{request_uri}/ [l,r=301]  # internally forward /dir/foo /dir/foo.php rewritecond %{request_filename} !-d rewritecond %{request_filename}.php -f rewriterule ^(.*?)/?$ $1.php [l] 

we can rewrite urls using .htaccess files. before writing in .htaccess files need verify kind of server using. can check server adding a

<?php phpinfo(); ?> 

in php page.

ensure mod_rewrite module enabled in apache server. can identified checking phpinfo included page.

common methods used url rewriting follows

rewriteengine

this mandatory apache server. used enable rewriting engine. in cases should on default.so ensure following code must mandatory in top of htaccess file

rewriteengine on 

rewriterule

in cases may have few pages , can specify each page in website in .htaccess file. in such case can use these kind of rewriting example

rewriterule ^article/used/to/be/here.php$ /article/now/lives/here/ [r=301,l] 

suppose have rewrite url these

http://en.wikipedia.org/wiki/url_rewriting

you should write these on .htaccess file

rewriteengine on rewriterule   ^wiki/(.+)$   w/index.php?title=$1   [l] actual implementation of page these 

http://en.wikipedia.org/w/index.php?title=url_rewriting

rewritecond

this can used rewriting url respect conditions. suppose need add or remove www website name , on condition redirect page "url not available or error message "

example :

rewritecond %{http_referer} !^http://(www.)?example.com/.*$ [nc]  

you can further refer here

introduction url rewriting

rewrite examples

these issues have not loading css files

style sheets files may treated without taking extension , wont load css. can following fixes on

  • use full path when including files in html pages

for example

<link href="css/style.css" rel="stylesheet" type="text/css" /> 

to

<link href="http://sitename.com/css/style.css" rel="stylesheet" type="text/css" /> 
  • move css project/public directory (like

  • project/public/css) use absolute paths css /css/index.css. make sure urls external files not rewritten server.

another solution try these method

rewritecond %{request_uri} !^.*\.(css|jpe?g|gif|png|js|ico)$ [nc] 

Comments

Popular posts from this blog

javascript - jQuery show full size image on click -