Problem using URL rewrite (Relative Paths not working)

一世执手 提交于 2019-11-30 09:17:36

问题


I am using a .htccess file in order to rewrite my URLs. I am using the following rules in my .htaccess files

Options +FollowSymlinks
RewriteEngine on 
RewriteBase /
RewriteRule ^product/([0-9]+)/([A-Za-z0-9+]+)$ /product.php?productid=$1&prodname=$2

The rewrite worked fine.

But when i try to access any other page through relative path which is in all the cases, the URL is not getting redirected properly.

Like in the below example

<form action "something.php" method="post">
   <input type="text" name="1" />
   <input type="submit" value="submit" />
</form>

When I click on submit, the page that gets loaded is http://mydomain/product/1/something/something.php which does not exist and hence throws a 404 error

I tried using the base tag in the head but this creates problem while I am using page anchors and modal windows. It gets redirected to the index page.

Please let me know if further details are required.

I am fairly new to this. So, could someone please help me with this?

Thanks in Advance, Kartik


回答1:


This is a URL resolving issue. See mod_rewrite URL info required for details.

You can either use absolute URL paths or absolute URLs:

<form action="/something.php" method="post">
<form action="http://example.com/something.php" method="post">

Or you change the base URL (see BASE HTML element) so that every relative URL is resolved from that URL and not the current URL:

<base href="/">
<base href="http://example.com/">



回答2:


The short and easy version of solving this is to absolute-path your URLs - /something.php in the form action, not just 'something.php'.



来源:https://stackoverflow.com/questions/938997/problem-using-url-rewrite-relative-paths-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!