i want to redirect my query base url to pretty url,i am trying this on local host, i want if any one try to access http://localhost/something/index.php?page=zen it will redirect to http://localhost/something/zen.html,
ie
http://localhost/something/index.php?page=zen => http://localhost/something/zen.html

RewriteEngine On
RewriteCond %{REQUEST_URI}  ^/index\.php$
RewriteCond %{QUERY_STRING} ^page=([a-zA-Z0-9_-])$
RewriteRule ^(.*)$ http://localhost/cmsmadesimple/%1.html [L,R=301]

Recommended Answers

In line 4, I think the %1 should be $1.

Jump to Post

Which page is the real one (that does processing)? The php or the html one? If the real one is the php one, then you're doing this backwards.

Jump to Post

To clarify, are you trying to rewrite a pretty URL i.e. website.com/page to a non pretty url i.e. website.com/index.php?page=page or are you trying to disallow a user from visiting a non-pretty URL by trying to redirect them back to the relevant pretty one?

Jump to Post

All 9 Replies

In line 4, I think the %1 should be $1.

no its not working with $1

Which page is the real one (that does processing)? The php or the html one? If the real one is the php one, then you're doing this backwards.

To clarify, are you trying to rewrite a pretty URL i.e. website.com/page to a non pretty url i.e. website.com/index.php?page=page or are you trying to disallow a user from visiting a non-pretty URL by trying to redirect them back to the relevant pretty one?

I think you'll end up with an infinite loop.

tell me what is solution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.