php - URL modified from each click after change in htaccess


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.

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

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



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=''>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>


Set a base in your head-Tag like this

 <base href="">

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


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.