I'm having a problem working out how to attach multiple "friendly url's" to my new project.
I've never had to work with multiple ones before so I don't know where to start. I had a play around but just couldn't come up with anything.
Original Script for one:
RewriteEngine on
RewriteCond %{REQ开发者_如何学PythonUEST_URI} \/([0-9a-z]{1,9})$ [NC]
RewriteRule ^(.*) http://mysite.me/?%1 [L]
I want to keep that exact one, but need more to handle other files, such as another couple of lines for this method;
view.php?p=46345
into mysite.me/view/46345
Hope you can help, Thanks!
I recommend you do all of this in your code rather than in Apache. Just redirect all requests to one file (index.php, or whatever your DirectoryIndex file is) and then examine the URL in your code and transform the URL into the form you want. Then, return a 301 with the transformed URL. If you want, you can skip this process for files that actually exist. This will avoid overhead for requested assets.
Here's a sample .htaccess that does this:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# check if the file exists. if it doesn't redirect to your main file
# comment out the RewriteCond if you don't want to skip index.php for existing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
精彩评论