我怎样才能利用外界信息的URL重写?(How can I get use outside information in url rewrites)

   IT问题网   2018-12-07 00:00:00

问 题

希望你们当中有些人的.htaccess大师可以帮助我这一个。我从来没有花任何时候与之前的.htaccess乱搞,所以我有点失去了。

基本上,我想借此链接,如 example.com/index.phpid=3并将其转换为 http://example.com/pagename/

这样的链接转换为 http://example.com/directory/3

解决方案

字press通过改写一切,没有解决的一个文件或目录的index.php ,它看起来是这样的:

rewriteengine叙述上
的rewritebase /
的rewritecond%{} request_filename!-f
的rewritecond%{} request_filename!-d
重写规则。的index.php [l]
 

和index.php文件读取请求的uri,并计算出如何处理它。与此同时,字press知道这些网址被改写,因此呈现干净的搜索引擎友好的url的页面,比如 http://example.com/pagename/

有关你的榜样,mod_rewrite的本身是不会要能够知道的 id = 3 的等同于的页面名称的,除非你狠codea一堆个人的规则集的。你可以做什么它做的index.php接受的页面名称的所以你的规则将是这个样子:

 的rewritecond%{} request_filename!-f
的rewritecond%{} request_filename!-d
重写规则^(。+)$ /index.phppage=$1 [l]
 

现在它是由产生干净的搜索引擎友好的url的内容。在内容管理系统,本身页通常存储在数据库中根据某种类型的标识。假设一个网页"测试页"与数据库为"5",10月10日创建的,2011年当cms需要生成一个链接,它会在数据库中,并构造的联系,的id / 2011/10 / test_page 。

所以,当你去,比方说,在头版,index.php文件生成链接到它的所有网页和"测试页",链接说 / 2011/10 / test_page ,当有人点击该链接,apache使用像重写规则^([0-9] +)/([0-9] +)/(。+)$ /指数规则2个月= $&功放; 1 .php年= $&放?标题= $ 3 [l] 重写url以 /index.phpyear=2011amp;month=10amp;标题= test_page 。在index.php脚本是在数据库中正确的页面,并返回给浏览器。这将是为每个cms不同。从本质上讲,的.htaccess不知道这是存储在数据库中任何东西,但它可以重写的链接,以便需要的信息(如"id"或"网页")被传递到脚本。它是由脚本既决定返回什么页面,以生成页面上的清洁搜索引擎友好的联系。

标签:怎样才能利用应用外界信息重写



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

基于URL到一个新的页面的RewriteCond重写规则进行的.htaccess,定期EX pression(RewriteCond RewriteRule for .htaccess based on URL to a new page, regular expression)

problem i have an interesting rewriterule and i am not su ...

的.htaccess,mod_rewrite的,正则表达式用目录和文件类型(.htaccess, mod_rewrite, regex with directory and filetype)

problem i want to do a rewrite with the following conditi ...

.htaccess的语言重定向310错误(Htaccess language Redirect 310 error)

problem i have a two language site swedish sidewww.site ...

重定向一切的index.php(Redirection everything to index.php)

problem i wan't to redirect everything to index.php exepe ...

生成SE友好的URL的.htaccess国防部重写(Generating SE friendly URL .htaccess mod rewrite)

problem i've a url which get file name through get method ...

htaccess的子域名重定向(htaccess subdomain redirect)

problem i've searched around and tried a few ...

UrlRewrite 3 GET请求(UrlRewrite with 3 get request)

problem i'm working on a project and stuck on urlrewrite. ...

mod_rewrite的:恶意重定向(Mod_ReWrite: Unwanted redirect)

problem possible duplicate: .htaccess, clean ...

限制用户子目录(limiting users to subdirectories)

problem i have a subdirectory of users that i want to lim ...

重定向子文件夹的.htaccess(Redirection Subfolder Htaccess)

problem i want a redirect using htaccess i have a post na ...

使用的.htaccess,从来没有表现出的index.php(Using .htaccess, never show index.php)

problem how can i never show index.phpfor example, all re ...

在子域的内部服务器错误(internal server error in subdomains)

problem i installed worpress to my main domain abcd.com. ...

基于用户代理手机网站重定向(Mobile website redirection based on user agent)

problem say i've got two distinct domains: ...

的Joomla htaccess的不工作(Joomla htaccess not working)

problem i am using joomla 1.7 and using joomla's built in ...

扩大友好的URL,国防部重写(Expanding friendly url, mod rewrite)

problem i am using modx, which is a cms system. it has a ...

共享主机Zend的项目?(zend project on shared hosting )

problem i created a zend project on localhost on ubuntu o ...

URL结构的htaccess(url construction htaccess)

problem lets say i have a link to one of my page that loo ...

htaccess的重写规则(.htaccess RewriteRule)

problem i'm trying to write a rewriterule (with no luck) ...

如何配置.htaccess文件的重写规则摆脱扩展,尾随斜线,WWW?(How to configure .htaccess file for rewrite rules to get rid of extensions, trailing slashes, www)

problem this is what i want - when somebody enters site. ...

htaccess的基础上与通配符和东西后,到index.php index.php页面重定向不存在的页面(.htaccess redirect non existing pages based on index.php page with wildcard and something after it to index.php)

problem please help, some website is arbitrar ...