获取页面的值id并通过的​​.htaccess的URL显示页面、id、URL、htaccess

2023-09-02 00:55:32 作者:软妹的小情书

我想在我们的.htaccess文件使用重写来显示搜索引擎友好的URL,但我不能让它工作(我研究过很多关于StackExhange和其他地方的相关主题,但都无济于事)。我想获得这个页面上的id的值...

I'm trying to display SEO friendly URLs by using a rewrite in our .htaccess file, but I can't get it to work (I've researched many of the related topics on StackExhange and elsewhere, but to no avail). I'd like to get the value of the id on this page...

http://199.119.123.135/info/tool​​_surety_company.php?id=1

...并在URL,而不是丑陋的显示值idtool_surety_company.php?ID = 1。

...and display the id value in the URL instead of the ugly "tool_surety_company.php?id=1".

我要为这样的结果: http://199.119.123.135/info/travelers-组

我用我的.htaccess中code:

I'm using the following code in my .htaccess file:

RewriteCond %{THE_REQUEST}  /+info/tool_surety_company.php?id=([^&]+)
RewriteRule ^ /info/%1/? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^^info/([^/]+)/?$ /info/tool_surety_company.php?id=$1 [QSA]

不过,我收到一个404错误。

But I'm receiving a 404 error.

任何想法?在此先感谢!

Any ideas? Thanks in advance!

推荐答案

有可能是什么我误会,但我相信,将需要在服务器端code的机制来加载正确的内容新的搜索引擎友好的URL。换句话说,当然,你可以将用户重定向到显示出不同的URL,但服务器将如何知道要加载的内容为新的网址是什么?

There might be something I'm misunderstanding here but I believe there would need to be a mechanism on the server side code to load the correct content for the new "seo-friendly url". In other words, sure, you can redirect the user to show a different url but how is the server going to know what content to load for that new url?

下面是组建了一个简单的例子,一个很好的资源。 的https://moz.com/ugc/using-mod-rewrite-to-convert-dynamic-urls-to-seo-friendly-urls

Here's a good resource for putting together a simple example. https://moz.com/ugc/using-mod-rewrite-to-convert-dynamic-urls-to-seo-friendly-urls

更新:

从这里 - 的https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules

故障排除

404未找​​到

仔细检查浏览器中的新的URL。是否匹配文件   存在由重写指定在新位置服务器上   规则?您可能需要让你的重写规则更加广阔(你可能会   能够从第二字符串中删除的$ 1)。这将直接   改写在第二个字符串中给出的主索引页。或者你   可能需要从旧的位置复制文件到新的位置。

Examine the new URL in your browser closely. Does it match a file that exists on the server in the new location specified by the rewrite rule? You may have to make your rewrite rule more broad (you may be able to remove the $1 from the second string). This will direct rewrites to the main index page given in the second string. Or, you may need to copy files from your old location to the new location.

在换句话说,你会得到一个404的唯一原因是因为服务器没有找到被请求作为URL在浏览器地址栏中可见定义的文件。

In other words, the only reason you would be getting a 404 is because the server does not find the file that is requested as defined in the URL visible in your browser address bar.

.htaccess的修改可以通过使用Apache模块mod_rewrite的启用,   这是最强大的Apache模块和功能之一   availale。 .htaccess的修改可以通过mod_rewrite的提供特殊   重写请求内部以及重定向请求的能力   外部。

Htaccess Rewrites are enabled by using the Apache module mod_rewrite, which is one of the most powerful Apache modules and features availale. Htaccess Rewrites through mod_rewrite provide the special ability to Rewrite requests internally as well as Redirect request externally.

在网址在浏览器的地址栏中保持相同的   要求它是一个内部重写,当URL发生变化外部   重定向正在发生。这是一个第一的,并且所述一个   了解mod_rewrite的时候最大的精神块人都有。

When the url in your browser's location bar stays the same for a request it is an internal rewrite, when the url changes an external redirection is taking place. This is one of the first, and one of the biggest mental-blocks people have when learning about mod_rewrite.

从这里开始更多信息: http://www.askapache.com/htaccess/modrewrite-tips-tricks.html

More info from here: http://www.askapache.com/htaccess/modrewrite-tips-tricks.html