hide url directory

2019-02-20 01:47发布

问题:

I have a website:

www.mydomain.com/subfolder/subfolder/index.php

How could always hide the directory names from the url. I mean always hide the 2 subfolders' names from the url as the page changes.
Example:
These urls:

www.mydomain.com/subfolder/subfolder/index.php
www.mydomain.com/subfolder/subfolder/about.php
www.mydomain.com/subfolder/subfolder/contact.php
...

Becomes:

www.mydomain.com/index
www.mydomain.com/about
www.mydomain.com/contact
...

I want to use the last mentioned urls for requesting these pages, too, without typing a horrible long url.

回答1:

you can find some good hints when you will look for mod_rewrite or mod rewrite in htaccess.



回答2:

If you have access to the Rewrite engine, you can use a simple rewriting pattern similar to this:

RewriteRule ^/(.*)$ /subfolder/subfolder/$1.php


标签: url