Rewrite Url .htaccess

2019-06-14 14:03发布

问题:

I have a site with many html page in different directory ,and .htaccess file

 http://mysite.com/index.html 
.
.
.
http://mysite.com/design/index.html
.
.
.
http://mysite.com/doc/ui/index.html
.
.
.

I want to rewrite all of index.html page to :

http://mysite.com/doc.php 
.
.
.
http://mysite.com/design/doc.php
.
.
.
http://mysite.com/doc/ui/doc.php
.
.
.

I have a single page doc.php & I want to all of my index.html page rewrite to this page and I can get query string url and get page value and $echo in doc.php

how can I do this ?

回答1:

If you a simply wanted to use something other than index.html as as Directroy Index page, than you don't need to do a URL re-write at all.

Just put this config option in your Apache host config:

DirectoryIndex doc.php index.html index.htm

This will give preference to your doc.php when you are accessing the server using directory name only. In other words requests with URL's like http://mysite.com or http://mysite.com/design will go to the doc.php file in those directories rather than index.html. If the directory doesn't have a doc.php file the server will then look for an index.html file.



回答2:

Hi saeed same question in stackoverflow or you can take help form this url

PHP url rewriting using htaccess



回答3:

Using the DirectoryIndex command, you can easily change the index. You can append multiple files for the server to try if the previous one isn't available by separating different filenames with a space on the same line. Try not to use rewrites if they're not necessary.

DirectoryIndex doc.php

Put the previous in a .htaccess file in your root directory and it should make your directory index doc.php instead of index.php/html.