URL Rewrite Causing Path Problem

Encountering an issue with URL REWRITING on my Debian/Nginx/PHP server.

Screenshot of the image issue

Facing problems with displaying images.

My Project Structure

  • Class
  • css
  • img
  • ...
  • and the file.php here

Non-functional Approach / Functional Approach

The unsuccessful method

If the image is located in /img/subfolder/img.svg

<img src="/img/subfolder/img.svg">

The successful method

If the image is stored in /img/img.svg

<img src="/img/img.svg">

URL Rewriting in Nginx

rewrite ^/(.)/(.)/(.*)$ /index.php?app=$1&page=$2&param=$3;

Any idea what mistake I might be making? What path should I use to access my images?

Appreciate your assistance.

Answer №1

If someone else is facing a similar issue, my solution might be of help.

I made adjustments to my rewriting rules as follows:

location / {
    try_files $uri $uri/ =404;
    rewrite ^/(.*)/(.*)/(.*)$ /index.php?app=$1&page=$2&param=$3;
}

To

location / {
    try_files $uri $uri/ =404;
}

location /app {
    rewrite ^/app/(.*)/(.*)/(.*)$ /index.php?app=$1&page=$2&param=$3;
}

The key difference is that the rewriting rule now only applies when accessing

mywebsite.com/app/...

Therefore, my new URLs are structured like this:

mywebsite.com/app/myapp/mypage/param

As opposed to:

mywebsite.com/myapp/mypage/param

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Interpret an array of PHP objects using jQuery Ajax

Trying to populate a website with data retrieved from a database through an array of objects using jQuery. For example: <?php function testFunction() { $data = array() $mydata = new stdClass; $mydata->example = 'test'; $data[] = $mydata ...

Error: Unexpected termination of data in JSON file on line 2, starting at the first character

I keep encountering an error while trying to execute a basic JSON request. Check out the following PHP code that contains the data: <?php header('Content-Type: application/json; charset=utf-8'); $wealth = array( "name" => &q ...

How to use PHP code to decode Instagram URLs and return Null values

Can anyone help with an issue regarding json_decode from Instagram URL? When using the following URL , it returns Null in PHP. $newwul = "http://www.instagram.com/username/?__a=1"; $xo = connect($newwul); $xx = json_decode($xo,tru ...

"Moisten" a JavaScript object instance using a JSON array, similar to the way PHP does

When populating PHP objects with data, I typically use the following method: public function hydrate(array $data){ foreach($data as $key=>$value){ $method = 'set'.ucfirst($key); if(METHOD_EXISTS($this,$method)){ ...

"Challenges Arising in Deciphering a Basic JSON Array

After countless attempts, I am still struggling to solve this issue. My PHP code is functioning properly, as it returns the expected data when "Grove Bow" is selected from the dropdown menu: [{"wtype":"Grove Bow","was":"1.55","wcc":"5","wbdmin":"12","wbdm ...

Transforming the output from fetchAll() into a well-

Currently, I'm utilizing fetchAll(PDO::FETCH_ASSOC) to query my self-made database using an SQL statement. In order to visualize the retrieved data, I am employing print_r(). The values returned by print_r() look like this: Array ( [0] => Array ( ...

In Yii2, is it possible to set the width for a specific column in the GridView widget?

Is there a way to specify the width for a certain column, such as 'file_name', in my Yii2 GridView? I've tried some suggestions from here, but none of them seem to work for me. I have also considered making columns resizable, but I'm u ...

Is it possible to execute PHP without using Ajax when clicking on a Font Awesome icon?

So, besides using Ajax, is there another solution to achieve the same result? Can a font-awesome icon be turned into a button without Ajax? In case you're unfamiliar with what I mean by a font-awesome icon, here's an example: <i id="like1" on ...

Linking the bridge between Woocommerce Subscription and Account Funds plugins

After purchasing two plugins, Woocommerce Subscriptions and Account Funds, which claim to be compatible in their documentation, I am attempting to create a Simple Subscription product that adds the product price as account funds for the user upon checkout, ...

Having trouble returning a view from a subfolder in Laravel 4 Resource?

I've just started working with Laravel 4 and I have a controller named "OrderController" that contains the following code: public function index() { return View::make('order.index'); } In my views directory, there is a subfolder ca ...

Utilizing jQuery Ajax to submit multiple forms using a single selector in one go

I'm having an issue with jQuery Ajax involving multiple forms. Each time I execute it, only the top form works properly while the others do not function as expected. Can anyone provide assistance with this? Here is the source code: <form id="form_ ...

Generate a standard Wordpress menu containing all pages without the need to manually add each page in the menu editor

I'm struggling to figure out how to display all pages in WordPress without manually adding them to a menu. Instead of creating a new menu and selecting specific pages, I want to automatically show all existing pages in the menu. For example, if I ha ...

Is there a way for me to insert PHP code into a file that has been generated by PHP?

I have encountered an issue where PHP files seem to convert all PHP code into emptiness. Despite creating a PHP file, adding PHP and HTML code to it, and then closing it, the code does not appear as expected in the file. I attempted a solution which is det ...

What is the best way to pass an array to PHP and then display it in HTML?

After setting up a form with 3 select tags in my HTML, I attempted to create an array using jQuery and send it to PHP. The goal is to retrieve data from PHP and display it on my HTML page. Below is the code snippet: HTML code <form name="myform"> ...

Pulling data from a MySQL database using AJAX and PHP to convert it into a JavaScript variable, resulting in

I am attempting to retrieve MySQL data using PHP, convert it to JSON, and then pass it into my JS variables for Chart.js. The JSON generated by PHP appears correct. However, when trying to access the data within my variables, the console is displaying them ...

utilizing session variables in php that are generated during an Ajax request

Hey there! I am facing an issue with accessing session variables after making an Ajax call in JavaScript to a PHP file. I am able to create a session and store values within it during the Ajax call, but when trying to access those session variables afterwa ...

jQuery Uploadify struggling with high resolution images

I've been using the jQuery Uploadify plug-in and it's been great, but I recently encountered an issue when trying to upload images larger than 2.5mb. Even though the process completes and shows that the file is 100% uploaded, the file never actu ...

Plugin for jQuery Validation: Verify if input is NOT an email address

I am currently updating a small Zend e-commerce website and we have been experiencing issues with robot inputs filling in email addresses in every field. To prevent this, I am looking to implement form validation that checks if the field does not contain a ...

Can data be transferred between browsers, such as from Google Chrome to Mozilla Firefox?

I have a dilemma with two separate pages—one for Admin and the other for User. The Admin page is named index.html <!DOCTYPE html> <html lang="en"> <head> <style> * { padding: 0; ...

Problem with Array Serialization

I have a situation where I am serializing information using jQuery and storing it in a MySQL database: $(function () { $("#sortable").sortable({ stop: function (event, ui) { $("#q35list").val($(this).sortable('serialize') ...