php - URL modified from each click after change in htaccess

483

i am modifying my php script to SEO friendly

when i click first time on link in test.php page it is displaying in url as htp://example/test/first working fine. when click on second time url as become htp://example/test/test/first.test folder is keep on adding into URL

how to reslove this issue.

##test.php
<html>
<head></head>
<body>
<a  href='test/first'>testing</a> <br>
<body> 
</html>

##.htaccess
RewriteEngine On
RewriteBase 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteRule ^test/(.+)  /test.php?$1 [L]
DirectoryIndex test.php
801

Answer

Solution:

Several possibilities to solve this.

1) Slash in front of the URL

 <a  href='/test/first'>testing</a>

which will only work if your website isn't contained in a sub directory of your web space

2) Absolute URL

 <a  href='http://www.example.com/test/first'>testing</a>

You can save this in a config file or something (baseUrl anyone?) and append it to links dynamically like this

 <a  href='<?=$cfg->baseUrl?>/test/first'>testing</a>

3) HTML

Set a base in your head-Tag like this

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

which might break other paths on your site like image-paths and CSS paths

People are also looking for solutions to the problem: php - Exception 'could not find driver' while migration in yii2

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.