e子目录的mapache重写规则

时间:2016-01-14 18:28:40

标签: php apache .htaccess mod-rewrite url-rewriting

我在我的本地计算机上为我的项目运行XAMPP。我有一个项目,我将项目文件放在c:\xampp\htdocs\newproject下。当我在localhost/newprojet浏览器中访问此项目时,它工作正常。但是源代码中的所有图像都被引用为src="/images/del.jpg"(以斜杠开头)。路径以斜杠开头,因此它在根目录下查找images文件夹c:\xampp\htdocs。如果我将images文件夹放在此文件夹中,则所有图像都会正确加载。但如果我将images文件夹放在c:\xampp\htdocs\newproject中,则浏览器会为404提供图片。我知道我使用apache rewrite rule但我无法弄明白一些规则。我在.htaccess文件中尝试了不同的规则,如:

DirectoryIndex default.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^images/(.*) images/$1 [NC,L]

也是这个:

DirectoryIndex default.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/images/(.*) images/$1 [NC,L]

但这些都不起作用。任何人都可以帮助我解决apache重写规则。

NOTE: I cannot change source of images from /images/someimage.png to images/someimage.png

这是我.htaccess内容的内容供参考。 DirectoryIndex default.php

选项+ FollowSymlinks

上的RewriteEngine
RewriteRule ^apis/creditCardCompany/([^/]*)/([^/]*) entities/CreditCardCompany.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/currency/([^/]*)/([^/]*) entities/Currency.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/currentTax/([^/]*)/([^/]*) entities/CurrentTax.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/customer/([^/]*)/([^/]*) entities/Customer.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/customerGroup/([^/]*)/([^/]*) entities/CustomerGroup.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/document/([^/]*)/([^/]*) entities/Document.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentLine/([^/]*)/([^/]*) entities/DocumentLine.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentNumerator/([^/]*)/([^/]*) entities/DocumentNumerator.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentPayment/([^/]*)/([^/]*) entities/DocumentPayment.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentPaymentType/([^/]*)/([^/]*) entities/DocumentPaymentType.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentTax/([^/]*)/([^/]*) entities/DocumentTax.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/employee/([^/]*)/([^/]*) entities/Employee.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/employeeGroup/([^/]*)/([^/]*) entities/EmployeeGroup.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/employeeStorage/([^/]*)/([^/]*) entities/EmployeeStorage.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/item/([^/]*)/([^/]*) entities/Item.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/itemGroup/([^/]*)/([^/]*) entities/ItemGroup.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/itemPricePerTaxRegion/([^/]*)/([^/]*) entities/ItemPricePerTaxRegion.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/itemSaleAlert/([^/]*)/([^/]*) entities/ItemSaleAlert.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/itemTag/([^/]*)/([^/]*) entities/ItemTag.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/language/([^/]*)/([^/]*) entities/Language.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/pos/([^/]*)/([^/]*) entities/PointOfSale.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/posType/([^/]*)/([^/]*) entities/PointOfSaleType.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/priceHistory/([^/]*)/([^/]*) entities/PriceHistory.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/storage/([^/]*)/([^/]*) entities/Storage.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/supplier/([^/]*)/([^/]*) entities/Supplier.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/tag/([^/]*)/([^/]*) entities/Tag.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/taxRegion/([^/]*)/([^/]*) entities/TaxRegion.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/taxType/([^/]*)/([^/]*) entities/TaxType.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/workingHour/([^/]*)/([^/]*) entities/WorkingHour.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/customerTitle/([^/]*)/([^/]*) entities/CustomerTitle.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/creditType/([^/]*)/([^/]*) entities/CreditType.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/dbBrowser/([^/]*)/([^/]*) entities/DBBrowser.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/transaction/([^/]*)/([^/]*) entities/Transaction.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/shvaReference/([^/]*)/([^/]*) entities/ShvaReference.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/refund/([^/]*)/([^/]*) entities/Refund.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getWorkingHour/([^/]*)/([^/]*) entities/GetWorkingHour.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getTransaction/([^/]*)/([^/]*) entities/GetTransaction.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getShvaReference/([^/]*)/([^/]*) entities/GetShvaReference.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getDocument/([^/]*)/([^/]*) entities/GetDocument.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getDocumentTax/([^/]*)/([^/]*) entities/GetDocumentTax.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getDocumentPayment/([^/]*)/([^/]*) entities/GetDocumentPayment.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getDocumentLine/([^/]*)/([^/]*) entities/GetDocumentLine.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentType/([^/]*)/([^/]*) entities/DocumentType.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/validationMethod/([^/]*)/([^/]*) entities/ValidationMethod.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/generalParameter/([^/]*)/([^/]*) entities/GeneralParameter.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/posParameter/([^/]*)/([^/]*) entities/PosParameters.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getRefund/([^/]*)/([^/]*) entities/GetRefund.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/buttonActionParameter/([^/]*)/([^/]*) entities/ButtonActionParameter.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/buttonAction/([^/]*)/([^/]*) entities/ButtonAction.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/buttonLayoutPage/([^/]*)/([^/]*) entities/ButtonLayoutPage.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/buttonLayout/([^/]*)/([^/]*) entities/ButtonLayout.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/object/([^/]*)/([^/]*) entities/Object.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/company/([^/]*)/([^/]*) entities/Company.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/dealer/([^/]*)/([^/]*) entities/Dealer.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/organization/([^/]*)/([^/]*) entities/Organization.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/specialPrice/([^/]*)/([^/]*) entities/SpecialPrice.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/message/([^/]*)/([^/]*) entities/Message.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/electiveModule/([^/]*)/([^/]*) entities/ElectiveModule.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/fixLabQuestionAnswerType/([^/]*)/([^/]*) entities/FixLabQuestionAnswerType.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/fixLabFixStatus/([^/]*)/([^/]*) entities/FixLabFixStatus.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/fixLabFixQuestion/([^/]*)/([^/]*) entities/FixLabFixQuestion.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/fixLabParameter/([^/]*)/([^/]*) entities/FixLabParameter.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/fixLabDocument/([^/]*)/([^/]*) entities/FixLabDocument.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/fixLabQuestionAnswer/([^/]*)/([^/]*) entities/FixLabQuestionAnswer.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/inventory/([^/]*)/([^/]*) entities/Inventory.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/inventoryItem/([^/]*)/([^/]*) entities/InventoryItem.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/tempInventory/([^/]*)/([^/]*) entities/TempInventory.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/tempInventoryItem/([^/]*)/([^/]*) entities/TempInventoryItem.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/documentError/([^/]*)/([^/]*) entities/DocumentError.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/commission/([^/]*)/([^/]*) entities/Commission.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/sort/([^/]*)/([^/]*) entities/GridUserSort.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/user/([^/]*)/([^/]*) entities/User.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/userLogin/([^/]*)/([^/]*) entities/UserLogin.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/default/([^/]*)/([^/]*) entities/ObjectDefault.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/label/([^/]*)/([^/]*) entities/Label.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/dashboard/([^/]*)/([^/]*) entities/Dashboard.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/companyLogo/([^/]*)/([^/]*) entities/CompanyLogo.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/modifierGroup/([^/]*)/([^/]*) entities/ModifierGroup.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/modifier/([^/]*)/([^/]*) entities/Modifier.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getPointsOfSaleData/([^/]*)/([^/]*) entities/GetPointOfSaleData.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/posLog/([^/]*)/([^/]*) entities/PosLog.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/getTable/([^/]*)/([^/]*) entities/GetTable.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/incometax/([^/]*)/([^/]*) entities/IncomeTaxOpenInterface.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/saronaMarket/([^/]*)/([^/]*) entities/SaronaMarket.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/sqlquerylog/([^/]*)/([^/]*) entities/SqlQueryLog.php?action=$1&companyCode=$2 [NC,L]

RewriteRule ^apis/servers/([^/]*)/([^/]*) entities/Servers.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/shvaErrors/([^/]*)/([^/]*) entities/ShvaErrors.php?action=$1&companyCode=$2 [NC,L]
RewriteRule ^apis/queries/([^/]*)/([^/]*) entities/Queries.php?action=$1&companyCode=$2 [NC,L]

RewriteRule ^apis/softwareVersion/([^/]*)/([^/]*) entities/SoftwareVersion.php?action=$1&companyCode=$2 [NC,L]

RewriteRule ^apis/checkTaxChange/([^/]*)/([^/]*) entities/CheckTaxChange.php?action=$1&companyCode=$2 [NC,L]

RewriteRule ^apis/appModule/([^/]*)/([^/]*) appModule.php?action=$1&companyCode=$2 [NC,L]



RewriteRule ^report/([^/]*)/([^/]*) entities/Report.php?name=$1&companyCode=$2


RewriteRule ^apis/([^/]*)/([^/]*)/([^/]*) handleAPIRequest.php?object=$1&command=$2&companyCode=$3 [NC,L]
RewriteRule ^device/([^/]*)/([^/]*)/([^/]*) handleDeviceRequest.php?object=$1&command=$2&companyCode=$3 [NC,L]
RewriteRule ^js/([^/]*)/([^/]*)/([^/]*)/([^/]*) handleScriptRequest.php?scriptFile=$1&localeCode=$2&token=$3&companyCode=$4 [NC,L]
RewriteRule ^css/([^/]*)/([^/]*)/([^/]*)/([^/]*) handleStyleRequest.php?cssFile=$1&localeCode=$2&token=$3&companyCode=$4 [NC,L]
RewriteRule ^upload/image/([^/]*) handleImageUpload.php?companyCode=$1 [NC,L]
RewriteRule ^data/merge/([^/]*)/([^/]*) handleDataMerge.php?language=$1&companyCode=$2 [NC,L]
RewriteRule ^data/import/([^/]*)/([^/]*) handleDataImport.php?language=$1&companyCode=$2 [NC,L]
RewriteRule ^data/export/([^/]*)/([^/]*) handleDataExport.php?language=$1&companyCode=$2 [NC,L]
RewriteRule ^excelData/export/([^/]*)/([^/]*) handleExcelDataExport.php?language=$1&companyCode=$2 [NC,L]
RewriteRule ^data/fastMerge/([^/]*)/([^/]*) fastHandleDataMerge.php?language=$1&companyCode=$2 [NC,L]

RewriteRule ^data/export/pdf handlePdfMaker.php [NC,L]

RewriteRule ^hello handleHello.php [NC,L]

RewriteRule ^image/barcode/([^/]*)/([^/]*)/([^/]*)/([^/]*) handleBarcode.php?barcode=$1&scale=$2&type=$3&digits=$4 [NC,L]

所有其他规则都工作得很好。我上面没有为images文件夹添加规则。

1 个答案:

答案 0 :(得分:0)

试试这个:

RewriteRule    ^$ images/    [L]
RewriteRule    (.*) images/$1 [L]