Rewrite question

My page1 code is

echo “<a href=page1/$page2.html>Go to page2</a>”;

page2 code is

echo “<a href=page2/$page1.html>Go to page1</a>”;

htaccess code is

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^page1/([a-zA-Z0-9_-]+)\.html$ http://localhost/Folder/page2.php
RewriteRule ^page2/([a-zA-Z0-9_-]+)\.html$ http://localhost/Folder/page1.php

in page1 when i click on Go to page2 its working and url is


in page2 when i click on Go to page1 its not working url showing


but url should to without page1


Yes, the part that needs to be matched is the same in both rules, so if the first one fires the second one never will. Apache can’t guess your intent :slight_smile:

That being said, if I see this correctly, all that matters is the page after the slash, right?

If so:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^page\\d+/page(\\d+)\\.html$ http://localhost/Folder/page$1.php


Sorry brother, i am not understanding…

i want to say - how can i refresh the url?


here previous /page 1/ is remaining…

You need to put a slash in front of the URL

// page 1
echo '<a href="/page1/page2.html">Go to page2</a>';

// page 2
echo '<a href="/page2/$page1.html">Go to page1</a>';