Rewrite question

My page1 code is

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

page2 code is

<?php
$page1=page1;
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

http://localhost/Folder/page1.php

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

http://localhost/Folder/page1/page2.html

but url should to without page1

http://localhost/Folder/page2.html

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

:slight_smile:

Sorry brother, i am not understanding…

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

http://localhost/Folder/page1/page2.html

here previous /page 1/ is remaining…

You need to put a slash in front of the URL


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

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