简体   繁体   English

从/example.php?id=1到/ example / of-page的Mod-rewrite url

[英]Mod-rewrite url from /example.php?id=1 to /example/title-of-page

I have a website that generates urls like: 我有一个生成网址的网站:

www.site.com/example.php?id=1 www.site.com/example.php?id=1

I would like that url to be displayed like: 我希望这个网址显示如下:

www.site.com/example/the-title-of-the-page-whatever-it-may-be www.site.com/example/the-title-of-the-page-whatever-it-may-be

Can I do this in .htaccess or do I need to edit the php or what? 我可以在.htaccess中执行此操作,还是需要编辑php或者什么?

Be gentle, and treat me like an idiot please - I'm brand new to all this :) 要温柔,请像对待白痴一样对待我 - 我对这一切都是全新的:)

Use this for your htaccess : 用于你的htaccess:

RewriteEngine On RewriteEngine On
RewriteRule ^([^/]*).html$ /example.php?id=$1 [L] RewriteRule ^([^ /] *)。html $ /example.php?id=$1 [L]

Your Old URL > example.com/example.php?id=1 您的旧网址> example.com/example.php?id=1
Will be change to > example.com/1.html 将更改为> example.com/1.html

Using id : 使用id:

RewriteEngine On RewriteEngine On
RewriteRule ^id/([^/]*).html$ /example.php?id=$1 [L] RewriteRule ^ id /([^ /] *)。html $ /example.php?id=$1 [L]

Your Old URL > example.com/example.php?id=1 您的旧网址> example.com/example.php?id=1
Will be change to > example.com/id/1.html 将更改为> example.com/id/1.html

Hope Help you ;) 希望能帮到你;)

如果您使用的是apache服务器,则可以使用mod重写

You indeed need an .htaccess file for this and of course some PHP code to see what page needs to be loaded. 你确实需要一个.htaccess文件,当然还需要一些PHP代码来查看需要加载的页面。 The .htaccess could look something like this: .htaccess看起来像这样:

# Start rewrite engine
RewriteEngine On

# Catch non existing files and/or folders (treat as optimized urls)
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Catch blocked folders (treat as optimized urls)
RewriteRule ^(.*)$ index.php [L]

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

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