简体   繁体   English

URL重写-PHP + Apache

[英]URL Rewriting - PHP + Apache

I wanna turn PHP dynamic URLs into static URLs. 我想将PHP动态URL转换为静态URL。 For example, I want URLs like 例如,我想要类似的网址

http://www.example.com/book.php?title=twilight to become http://www.example.com/book/twilight http://www.example.com/book.php?title=twilight成为http://www.example.com/book/twilight

and http://www.example.com/writer.php?name=meyers to become http://www.example.com/writer/meyers http://www.example.com/writer.php?name=meyers成为http://www.example.com/writer/meyers

When it's done, will my form validation on the site change? 完成后,我在网站上的表单验证会更改吗?

My URL rewriting needs might not be much too complicated. 我的URL重写需求可能不会太复杂。

I'm developing it locally using XAMPP, Apache and MySql. 我正在使用XAMPP,Apache和MySql在本地开发它。 Later I'll put it online. 稍后,我将其放在网上。

How do I do that? 我怎么做? Is this kind of URL rewriting technique the most adviced for SEO? 这种URL重写技术是否最适合SEO?

You would use mod_rewrite for that. 您将为此使用mod_rewrite If you do a bit of searching on here for that, you'll likely find lots of other questions about how to create mod_rewrite rules similar to what you want to do. 如果您在此处进行一些搜索,您可能会发现很多其他问题,如关于如何创建类似于您想要执行的mod_rewrite规则的问题。

Yep. 是的。 U need to use mod_rewrite. 您需要使用mod_rewrite。 Also do a search for .ht_access files. 还搜索.ht_access文件。 You can put your rewrite directives in .ht_access files and drop them in to whatever directory on your server where you want them to take effect. 您可以将重写指令放在.ht_access文件中,并将它们放到服务器上您希望它们生效的任何目录中。

For the type of rewrite you want this rule generator should be of use to you: 对于您想要的重写类型,此规则生成器应该对您有用:

http://www.generateit.net/mod-rewrite/ http://www.generateit.net/mod-rewrite/

And yes the URL you're trying to achieve is seo friendly. 是的,您尝试获得的URL是seo友好的。

You can use a .htaccess file (or better apache.conf) to forward all requests to index.php with mod_rewrite: 您可以使用.htaccess文件(或更好的apache.conf)通过mod_rewrite将所有请求转发到index.php:

Options +FollowSymLinks
IndexIgnore */*

<ifmodule mod_rewrite.c> 
RewriteEngine on

    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # otherwise forward it to index.php
    RewriteRule . index.php
</ifmodule>

There you can use $_SERVER['REQUEST_URI'] to interpret the request. 在那里,您可以使用$_SERVER['REQUEST_URI']解释请求。

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

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