PHP网站:在没有实际存在的情况下使URL /路径存在

This might be a stupid question...

I have a website with a lot of data, and I need each page indexed by search engines. There will be hundreds of thousands of pages. Instead of storing 400,000 php files and folders on my server is there an alternate way to show that a file exists to a search engine / user and generate a page without actually storing it in the file system? Another side-effect of this issue is that all the ftp programs I'm using also seem to limit the number of folders that you can view, so I can't easily access the files or folders that I've generated.

The site is generated with PHP.

I need the urls to look like this:
mysite.com/folder/12345678/this-is-a-description
Currently I have 400,000 12345678 (but unique) folders, and 400,000 (unique) this-is-a-description.php

It sounds like you need to use Apache's mod_rewrite or an Nginx depending on your web server. Digital Ocean has quite an extensive tutorial on how to set this up.

You could also use a third party routing library like Symfony's routing component, which is quite extensive and has everything set up already.

yes, it's easy, for example, if you use Apache just redirect everything using htaccess to a file, and then show the content you want.

Example

.htaccess:

RewriteEngine On
RewriteBase /

RewriteRule ^([0-9a-zA-Z-_]*)\/?([0-9a-zA-Z-_]*)\/?([0-9a-zA-Z-_]*)\/?([0-9a-zA-Z-_]*)\/?$ /index.php?a=$1&b=$2&c=$3&%{QUERY_STRING}

this will redirect mysite.com/folder/12345678/this-is-a-description to

/index.php?a=folder&b=12345678&c=this-is-a-description

then, in index.php you should check this variables ($_REQUEST['a'], $_REQUEST['b'] and $_REQUEST['c']) and show the content you want.

you don't need to create that much folders and files. your data should be in database, right? you just need to config .htaccess file to handle your urls. that will be easy to do and i think that is what you are looking for

for example you can config .htaccess file so that if url is like :

mysite.com/folder/12345678/this-is-a-description

the data comes from :

mysite.com/index.php?folder=12345678&data=this-is-a-description

you can easily find the solution to how to do that.

this will be the correct way to handle your website's data.

Create a file named .htaccess with the following code inside it

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([a-z0-9-_.]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^([a-z0-9-_.]+)/([a-z0-9]+)/?$ index.php?id=$1&goto=$2 [NC,L]

so what it does is: you can have the index.php page in the directory you want for example if you have

mysite.com/folder/ or mysite.com/folder/index.php once you do mysite.com/folder/anything_here.php it will be acessing the index.php file but with another page name , all your code should be in the index.php file.

</div>