简体   繁体   中英

URL rewrite problems

I wanted to pass the parameters to my PHP page in a friendly fashion, so here's what I wrote in .htaccess file

 RewriteRule ^confirm\/(([a-z0-9]).+)\/(([a-z0-9]).+)$ www.example.com/confirm.php?email=$1&order=$2

its working well, and I can get the parameters in PHP using

explode('/', $_SERVER['REQUEST_URI'])

I have 2 problems though,

1- when I submit this page, I need it to go directly to confirmation.php, instead it submits to www.example.com/confirm/example@mail.com/12-HDYF/confirmaction.php !!! how can this be changed.

2- the page was originally working perfectly, but when I type the friendly URL all jquery files give me the below error, which really seems unrelated.

在此处输入图片说明

Change your url structure to avoid ^confirm for both raw and friendly URL, that should make things easier to debug (and avoid loops). This is a guess since you haven't posted your input that fails.

RewriteRule ^orderconf\/(([a-z0-9]).+)\/(([a-z0-9]).+)$ www.example.com/confirm.php?email=$1&order=$2

That is because the client (the browser) sees the page it is browsing as www.example.com/confirm/example@mail.com/12-HDYF/ and when it analyzes it and parses the html, it sees it something like:

<script src="jquery.js"></script>
<form action="confirmation.php"... >

So the browser sees relative urls to the page he is at the moment. So if you tell him to search the jquery.js file in the same folder as the one he currently is, he is going to try to download from www.example.com/confirm/example@mail.com/12-HDYF/jquery.js , and the same thing happens when you submit the form.

To avoid this, use absolute URLs (note the leading slash):

<script src="/jquery.js"></script>
<form action="/confirmation.php"... >

If you have your files in a subfolder of the DocumentRoot , put that subfolder at the beginning of the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM