1

I currently am working on a project where I have to pass three parameters in the url. My url looks like -

localhost/newproject/index.php?file_name=clients&mode=edit&id=1

The functions that I perform when passing different parameters are listed below

1) url - localhost/newproject/index.php?file_name=clients

Function - include the file templates/modules/clients/clients.php

2) url - localhost/newproject/index.php?file_name=clients&mode=edit

Function - include the file template/modules/clients/cliemts-edit.php. And the clients-edit screen will be used to add a new client as the client id is not set.

3) url - localhost/newproject/index.php?file_name=clients&mode=edit&id=1

Function - include the file template/modules/clients/cliemts-edit.php. And the clients-edit screen will be used to update the client whose client_id is 1. Now, I am trying to convert this url to this

localhost/newproject/clients/edit/1

I have the following code in my htaccess

RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?file_name=$1&mode=$2&id=$3 [L]
RewriteRule ^([^/\.]+)$ index.php?file_name=$1 [L]

The problem that I am facing is that whenever the clients-edit screen gets included, the path of the css files, javascript files and the images get changed. How can I overcome this?

4

1 回答 1

0

你在正确的轨道上。

尝试:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ index.php?file_name=$1&mode=$2&id=$3 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ index.php?file_name=$1&mode=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ index.php?file_name=$1 [L]

为了修复 css/scripts,您需要使链接成为绝对 URL(它们以 a 开头/)或在页面标题中包含相对 URI 基础:

<base href="/" />
于 2013-09-19T07:33:32.293 回答