简体   繁体   English

.htaccess使用多个SEO友好URL

[英].htaccess working with multiple SEO friendly URL's

I'm having a problem working out how to attach multiple "friendly url's" to my new project. 我在解决如何将多个“友好的URL”附加到我的新项目时遇到问题。

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   %{REQUEST_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 view.php?p=46345 mysite.me/view/46345进入mysite.me/view/46345

Hope you can help, Thanks! 希望能对您有所帮助,谢谢!

I recommend you do all of this in your code rather than in Apache. 我建议您在代码中而不是在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. 只需将所有请求重定向到一个文件(index.php或任何DirectoryIndex文件),然后检查代码中的URL并将URL转换为所需的形式。 Then, return a 301 with the transformed URL. 然后,返回带有转换后的URL的301。 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: 这是执行此操作的示例.htaccess:

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM