
882 So.2d 869 (2003)
Rex HARTLEY
v.
STATE of Alabama.
2020799.
Court of Civil Appeals of Alabama.
December 12, 2003.
*870 Rex Hartley, pro se.
Andrew W. Redd, gen. counsel and asst. atty. gen., Department of Corrections, for appellee.
PER CURIAM.
Rex Hartley, an inmate at the Easterling Correctional Facility ("the facility"), appeals from the dismissal of the underlying action in the Barbour Circuit Court in which he filed, pro se, a "Civil Complaint for Declaratory Judgment" ("the complaint") against the facility's warden. Hartley contends that the trial court erred in construing his complaint as a petition for a writ of habeas corpus, and he asks for various forms of relief to correct the alleged error.
Hartley contended in his complaint that the prohibition against cruel and unusual punishment in the Eighth Amendment to the United States Constitution and his Fourteenth Amendment right to equal protection under the law are being violated by the warden of the facility because, he alleged, he and other inmates have no shelter to protect them from the elements when they walk from their cell blocks to the facility's kitchen, laundry room, and infirmary. As a result, he contended, the inmates get wet when it rains, and, unless they have a change of clothes, the inmates must wear their wet clothes for the remainder of the day. Hartley averred that, "[d]epending on the temperature, a walk in the rain can result in mental anguish, physical suffering, and discomfort." Hartley requested a declaration that this treatment violates his constitutional rights under the Eighth and Fourteenth Amendments, and he moved for an injunction requiring the facility either to build a covered walkway from the inmates' cell blocks to the other buildings they must go to or to provide "full body" raincoats free of charge to indigent inmates who cannot *871 afford to buy raincoats from the facility's store.
Hartley filed his complaint on December 17, 2002. The State filed a motion to dismiss the complaint on February 3, 2003, arguing that venue for the action was proper in Montgomery County, not in Barbour County. On February 18, 2003, the circuit court dismissed Hartley's action, stating, in pertinent part:
"The above-styled Petition for Writ of Habeas Corpus being considered by the Court along with the Motion to Dismiss filed by the Respondent, the Court is of the opinion that the motion is well taken and the above-styled petition is due to be dismissed and denied.
"It is therefore ordered, adjudged, and decreed that the above-styled Petition for Writ of Habeas Corpus be dismissed."
On March 7, 2003, Hartley appealed to the Court of Criminal Appeals, which transferred the case to this court due to lack of subject-matter jurisdiction.[1]
Hartley contends that the circuit court erred in construing his complaint as a petition for the writ of habeas corpus, and he requests that this court order the circuit court to rescind its dismissal order and either (1) transfer the case to the Montgomery Circuit Court, where proper venue lies, or (2) enter an order dismissing the case without prejudice so that he can refile his complaint in the Montgomery Circuit Court.
In its brief to this court, the State agrees that proper venue lies in the Montgomery Circuit Court. However, the State contends that even if the Barbour Circuit Court incorrectly construed Hartley's complaint as a petition for a writ of habeas corpus, its dismissal of the action was sufficient to provide to Hartley one of the two alternative forms of relief he seeks in this appeal, namely, enabling Hartley to refile his complaint in the Montgomery Circuit Court.
Both parties are correct in their assessment that Barbour County is not the proper venue in which to file Hartley's complaint. Section 6-3-9, Ala.Code 1975, states, in pertinent part: "All actions where the prison system or the state on account of the prison system is interested must be commenced in Montgomery County in any court having jurisdiction of the amount involved...." Hartley's suit against the warden of the facility based on the conditions at the facility is an action against the state prison system and thus should be filed in the Montgomery Circuit Court.
Both parties are also correct that the circuit court erred in construing Hartley's complaint as a petition for a writ of habeas corpus rather than as a civil action alleging violations of constitutional rights involving conditions of confinement.
"The relief [an inmate] seeks from alleged cruel and unusual treatment in the prison system is not cognizable under a writ of habeas corpus, and the appropriate remedy in this case for the claim of illegal conditions of confinement, if proved, would not be release from custody....
"`[T]he sole function of habeas corpus is to provide relief from unlawful imprisonment or custody, and it cannot be used for any other purpose.'"
Taylor v. State, 455 So.2d 270, 270-71 (Ala.Crim.App.1984) (quoting Cook v. Hanberry, 592 F.2d 248, 249 (5th Cir.1979), revised, 596 F.2d 658 (5th Cir.1979)). *872 Hartley does not seek relief from his imprisonment; rather, he seeks a change in certain conditions at the prison facility in which he is housed. Therefore, the circuit court erred in construing Hartley's complaint as a petition for a writ of habeas corpus.
Even though the circuit court construed the complaint incorrectly, that action was harmless error in relation to the relief requested by Hartley on appeal. Hartley requests that this court recognize that he filed a civil action and order the trial court to either transfer venue to Montgomery County or to dismiss the case without prejudice so that Hartley may refile the complaint in Montgomery County. The circuit court dismissed what it incorrectly construed to be a petition for a writ of habeas corpus on the ground of improper venue.[2] A dismissal of a petition for a writ of habeas corpus on the basis of improper venue is without prejudice. See, e.g., Brooks v. Alabama Bd. of Pardons & Paroles, 644 So.2d 481, 483 (Ala.Crim.App.1994) ("`[A] denial of habeas corpus is not res judicata. The principle of res judicata is inapplicable in habeas corpus petitions.'") (quoting Teat v. State, 636 So.2d 697, 698 (Ala.Crim.App.1994) (citations and emphasis omitted)); Campbell v. State, 436 So.2d 7, 7 (Ala.Crim.App.1983) (overruling rehearing on court's affirmance of trial court's dismissal of a petition for a writ of habeas corpus on the ground of improper venue, stating that the dismissal was without prejudice).
Thus, because the trial court treated Hartley's complaint as a petition for a writ of habeas corpus, the trial court's dismissal of that complaint on the basis of improper venue was necessarily without prejudice. The relief Hartley requests from this court is therefore unnecessary. Hartley is free to refile his complaint in the Montgomery Circuit Court. Accordingly, we affirm the judgment of the circuit court.
AFFIRMED.
YATES, P.J., and THOMPSON, PITTMAN, and MURDOCK, JJ., concur.
CRAWLEY, J., concurs in the result, without writing.
NOTES
[1]  This court subsequently transferred the case to the Alabama Supreme Court; that court transferred the case back to this court, pursuant to § 12-2-7(6), Ala.Code 1975.
[2]  We note, however, that if Hartley's petition had been a petition for a writ of habeas corpus, it would appear that § 15-21-6(a), Ala.Code 1975, would have been applicable. That section requires that when a petitioner is confined in a penitentiary, a petition for a writ of habeas corpus "must be addressed to the nearest circuit court judge," which has been construed to mean that the petition must be filed in the county in which the inmate is incarcerated. See, e.g., Anderson v. State, 710 So.2d 491 (Ala.Crim.App.1997).
