8

I have a peculiar situation, my website is like

www.example.com/page.php?url=homepage
. I am trying to use .htaccess file to make url look like

www.example.com/page/homepage/

There by hiding the ".php?url=" part in the url. is this possible? please suggest.

3 Answers 3

12

Try this:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /anything/anything -> anything.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_])/([^/]*)$ /$1.php?url=$2 [L]

</IfModule>

If the page.php filename will always be the same, then do it like this:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /page/anything -> page.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ /page.php?url=$1 [L]

</IfModule>
Sign up to request clarification or add additional context in comments.

1 Comment

I want to view the URL like example.com/blog/new-post instead of example.com/blog/blog-page.php?blog=new-post using htaccess. Thank you in advance...
4
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/(.*)/$ /page.php?url=$1 [L]

Comments

1

This code you can hide you page name

RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$  pagename.php?name=$1&id=$2    [NC,L] 

Comments

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.