Url-. htaccess hides index. php and uses pathinfo to cause cssjs loading errors.

Source: Internet
Author: User
I made a simple php framework and used & quot ;? The url view in the form of varval1 & amp; var2val2 & quot; is loaded normally. In apache, to beautify the url, use. the htaccess rule hides the index. php uses the url in pathinfo format. The page and data can be loaded, but css, js... I made a simple php framework and used" ?var=val1&var2=val2"Url view loading is normal,
apacheTo beautify the url, use Hide index. php by using the. htaccess ruleAnd Use pathinfo formatThe url, page, and data can be loaded, but the path of css and js files is changed to the pathinfo format. url/ public/css/style.cssThe loading path of css and js is incorrect. Find a correct. htaccess rule to load the Style File correctly.

Current error:
The project framework is placed under the capframework folder under the root directory of the site,
Usehttp://127.0.0.1/capframework/Access all OK, css load OK,
css urlIs:http://127.0.0.1/capframework/public/css/captain.css
When usinghttp://127.0.0.1/capframework/article/list/tag/phpDuring access, css and js problems occur, and the path becomes
http://127.0.0.1/capframework/article/list/tag/public/css/captain.css

Currently, the following rules are used:


  
   
RewriteEngine on RewriteCond % {REQUEST_FILENAME }! -D RewriteCond % {REQUEST_FILENAME }! -F RewriteRule ^ (. *) $ index. php/$1 [QSA, PT, L]
  Ask experts for advice and solve the problem

Reply content:

I made a simple php framework and used"?var=val1&var2=val2"Url view loading is normal,
apacheTo beautify the url, useHide index. php by using the. htaccess ruleAndUse pathinfo formatThe url, page, and data can be loaded, but the path of css and js files is changed to the pathinfo format.url/public/css/style.cssThe loading path of css and js is incorrect. Find a correct. htaccess rule to load the Style File correctly.

Current error:
The project framework is placed under the capframework folder under the root directory of the site,
Usehttp://127.0.0.1/capframework/Access all OK, css load OK,
css urlIs:http://127.0.0.1/capframework/public/css/captain.css
When usinghttp://127.0.0.1/capframework/article/list/tag/phpDuring access, css and js problems occur, and the path becomes
http://127.0.0.1/capframework/article/list/tag/public/css/captain.css

Currently, the following rules are used:


  
   
RewriteEngine on RewriteCond % {REQUEST_FILENAME }! -D RewriteCond % {REQUEST_FILENAME }! -F RewriteRule ^ (. *) $ index. php/$1 [QSA, PT, L]
  Ask experts for advice and solve the problem

This is not a problem with. htaccess. The reference to css in your code is similar to this:


  

Then, when your page path ishttp://127.0.0.1/capframework/article/list/tag/phpThe css path that the browser considers to be under the current directory and splicedpublic/css/captain.css, So it becomeshttp://127.0.0.1/capframework/article/list/tag/public/css/captain.css.

So you need


  

But this is still wrong, because the browser will think that the css path strength ishttp://127.0.0.1/public/css/captain.css.

Therefore, you also need to manually add the root directory


  

However, the root directory is generally not a definite thing, so it needs to be changed. Almost all php frameworks provide such variables.

No. ht file errors: when the file corresponding to the link exists, the returned file is limited. When the file cannot be accessed directly through the link, the relevant rules will be matched.

The initialization file should contain WEB_ROOT, which is written in the template file.
{WEB_ROOT} / public/css/captain.cssIt should be OK.

The css path is declared incorrectly. method 1, in

Statement Is the Basic path settings. Method 2: Use the absolute path when referencing css, as shown in figure

$ BaseUrl should be http: // 127.0.0.1/capframework/public/
In addition, for the sake of security ,. htaccess should be placed under public. If you configure a virtual host, it should also point to/capframework/public instead of/capframework, so as to avoid exposing other code. Of course, index. php should also be under public.

Upstairs !! Add'/'You can.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.