简体   繁体   English

URL重写-如何将example.com/pageid.php?id=12转换为example.com/full-title

[英]URL rewriting- How can I turn example.com/pageid.php?id=12 to example.com/full-title

I want to make my pages search engine friendly and it also looks better that example.com/pageid.php?id=12 我想让我的页面搜索引擎友好,并且example.com/pageid.php?id=12也看起来更好

I have pages different pages like showUser.php showLocation.php and I want all these to be rewritten. 我有不同的页面,例如showUser.php showLocation.php ,我希望所有这些页面都被重写。

Wo'nt mod_rewrite slow down my app a little bit? mod_rewrite会使我的应用程序变慢一点吗?

您需要看一下mod_rewrite(只要您的主机支持它)-这是一篇有关该主题的不错的博客文章

In your particular example, mod_rewrite could be set up something like this: 在您的特定示例中,可以将mod_rewrite设置如下:

# .htaccess
RewriteEngine on
RewriteRule ^/([\w-]+)$ /page.php?title=$1

Now, a request to /full-title would resolve to page.php and $_GET['title'] would hold the value 'full-title' . 现在,对/full-title的请求将解析为page.php$_GET['title']将保留值'full-title'

(Most web frameworks (such as Symfony, Django etc.) allow for customizable URL routing rules which do not require you to hardcode rewrite rules in your .htaccess file.) (大多数Web框架(例如Symfony,Django等)允许使用可自定义的URL路由规则,这些规则不需要您对.htaccess文件中的重写规则进行硬编码。)

暂无
暂无

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

相关问题 如何将example.com/index.php#anchor的URL重写为example.com/anchor? - How do I rewrite the URL for example.com/index.php#anchor to example.com/anchor? 使用,htaccess将example.com?id=12重定向到example.com/index.php?id=12 - using ,htaccess redirect example.com?id=12 to example.com/index.php?id=12 如何让所有 example.com 页面重定向到 example.com/smth - How can I make all example.com pages redirect to example.com/smth 如何从这个example.com/index.php?lang=en更改我的多语言网址到这个example.com/en/? - How can I change my multilingual urls from this example.com/index.php?lang=en to this example.com/en/? 将example.com/section.php?username=xyz重写为example.com/xyz/section - Rewriting example.com/section.php?username=xyz to example.com/xyz/section 如何从像“example.com/products/123/title-of-this-product”这样干净的 url $_GET['id']? - How to $_GET['id'] from a clean url like "example.com/products/123/title-of-this-product"? htaccess将example.com/user.php?id=username重写为example.com/username - htaccess rewrite example.com/user.php?id=username to example.com/username 如何将example.com/forum/index.php重定向到example.com/forum/ - How to redirect example.com/forum/index.php to example.com/forum/ 如何处理从example.com/search/?s=some到example.com/search/some的URL - How to manipulate the URL from example.com/search/?s=some to example.com/search/some 如何将example.com/index.php/lib更改为example.com/lib? - How to change example.com/index.php/lib to example.com/lib?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM