简体   繁体   English

使用.htaccess将子目录用作参数

[英]Using .htaccess to use subdirectory as a parameter

I've had a real tough time trying to search for the exact htaccess code that will allow me to do the following: 我一直在努力寻找确切的htaccess代码,这使我能够执行以下操作:

Visiting: http://www.domain.com/wildcard 造访: http : //www.domain.com/wildcard

Should show: http://www.domain.com/ 应该显示: http : //www.domain.com/

But the URL should still read: http://www.domain.com/wildcard 但是该网址仍应显示为: http : //www.domain.com/wildcard

So basically a transparent redirection... seems fairly straight-forward, but surprisingly hard to search for. 因此,基本上,透明的重定向...似乎很简单,但令人惊讶的是很难进行搜索。 The PHP in index.php is already set up to parse the subdirectory and read it as a parameter, but unfortunately my client never supplied me with the .htaccess file. 已经将index.php中的PHP设置为解析子目录并将其读取为参数,但是不幸的是,我的客户端从未向我提供.htaccess文件。 #developerproblems #developer问题

Thanks! 谢谢!

You just need this ErrorDocument 404 line at top of your .htaccess: 您只需要在.htaccess顶部的ErrorDocument 404行:

ErrorDocument 404 /

This will show home page for any request that is not a file or directory and results in a 404. 这将显示主页的所有非文件或目录请求,并显示404。

We will suppose that you have to receive a url parameter called param so your rewrite rule should be: 我们将假设您必须接收一个称为param的url参数,因此您的重写规则应为:

RewriteEngine On
RewriteRule ^([^/]*)$ /?param=$1 [L]

By this way any http://www.domain.com/AnythingHere will render the contents of http://www.domain.com/?param=AnythingHere so the home page is rendered. 通过这种方式任何http://www.domain.com/AnythingHere将呈现的内容http://www.domain.com/?param=AnythingHere使主页呈现。

However, such solutions, they are not change the contents, they may leads to SEO problems for repeated contents, So the solution of anubhava is better for SEO according to your usage. 但是,此类解决方案不会更改内容,可能会导致重复内容出现SEO问题,因此,根据您的使用情况, anubhava解决方案更适合SEO。

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

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