1

i want rewrite my url this is my index.html page

<a href="http://localhost/htac/index.php?url=main&page=1">Main</a> <br>
<a href="http://localhost/htac/index.php?url=about&page=2">About</a> <br>
<a href="http://localhost/htac/index.php?url=contact&page=3">Contact</a> <br>

this is my .htacees file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^/([a-z])/([0-9])?$ index.php?url=$1&page=$2 [L]

i want change my url to

http://localhost/htac/index/about/2 (http://localhost/htac/index/{url}/{page})

but url is :

http://localhost/htac/index.php?url=about&page=2
2
  • So did you try http://localhost/htac/index/about/2 to see if it resolves? Commented Oct 28, 2014 at 7:12
  • no, not working this link Not Found The requested URL /htac/index/about/2 was not found on this server. Commented Oct 28, 2014 at 7:14

1 Answer 1

2

Have your /htac/.htaccess like this:

RewriteEngine on
RewriteBase /htac/

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /index\.php\?url=([^\s&]+)&page=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&page=$2 [L,QSA]

You need to change source of your HTML to have links as: <a href="http://localhost/htac/main/1">Main</a>

Sign up to request clarification or add additional context in comments.

12 Comments

IMO /index/ should also be avoided from pretty URL. That's why I wrote a note on what the pretty URL should be.
i want rewrite with htacces
@Beginner add this code to htaccess this is for htaccess
@Beginner Then start by using a valid URL! The answer of anubhava is correct.
@anubhava ps. I would also add the NC parameter.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.