的.htaccess URL重写挑战 [英] .htaccess URL rewriting challenge

查看:239
本文介绍了的.htaccess URL重写挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法与某些URL重写。

所有的东西,下面的工作正常,但我需要添加从URL中去除查询字符串的规则。

site.com/page?a=b 将成为 site.com/page

有人可以帮帮忙?我已经做了的.htaccess一些阅读,但我觉得它非常复杂。另外,需要知道该文件在我的新指令应该出现。

感谢。


    #EE 404页缺页
    ErrorDocument的404 /index.php/404/index

    #简单的404丢失的文件
    
      的ErrorDocument 404找不到文件
    

    #重写可能已经上,取消,如果它不是
    
    RewriteEngine叙述上
    的RewriteBase /
    

    #阻止访问隐藏,其名称以期目录。本
    #包括使用版本控制系统,如颠覆或Git的目录。
    
      重写规则(^ | /)\。 - [F]
    

    #去除WWW  - 取消注释来激活
    #
    #的RewriteCond%{} HTTPS!=上
    #的RewriteCond%{HTTP_HOST} ^ WWW \。(。+)$ [NC]
    #重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]
    #

    #删除尾随斜线路径,不带扩展名
    #取消激活
    #
    #重写规则^(。*)/ $ / $ 1 [R = 301,L]
    #

    #删除的index.php
    #使用包括法
    #HTTP://ex$p$pssionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
    #
    的RewriteCond%{QUERY_STRING}!^(ACT =。*)$ [NC]
    的RewriteCond%{REQUEST_URI}!(\。[A-ZA-Z0-9] {1,5})$
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d
    的RewriteCond%{REQUEST_URI} ^/(home|inc|publishers|sidebars|about|include-template|testing|advertisers|products|sitemap|style|ad-choices|social-bar|search|404||members|P[0-9]{2,8}) [NC]
    重写规则(。*)/index.php/$1 [L]

解决方案

这会从URL中删除查询字符串

 重写规则^(。*)/index.php/$1? [L] #remove查询字符串
 

希望它可以帮助

I'm having trouble with some URL rewriting.

All of the stuff below works fine, but I need to add a rule which removes querystrings from URLS.

site.com/page?a=b will become site.com/page

Can someone help out? I have done some reading on .htaccess but I find it terribly complex. Also, will need to know where in the file my new directives should appear.

Thanks.


    # EE 404 page for missing pages
    ErrorDocument 404 /index.php/404/index

    # Simple 404 for missing files
    
      ErrorDocument 404 "File Not Found"
    

    # Rewriting will likely already be on, uncomment if it isnt
    
    RewriteEngine On
    RewriteBase /
    

    # Block access to "hidden" directories whose names begin with a period. This
    # includes directories used by version control systems such as Subversion or Git.
    
      RewriteRule "(^|/)\." - [F]
    

    # remove the www - Uncomment to activate
    #
    #  RewriteCond %{HTTPS} !=on
    #  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    #  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    # 

    # Remove the trailing slash to paths without an extension
    # Uncomment to activate
    # 
    #   RewriteRule ^(.*)/$ /$1 [R=301,L]
    # 

    # Remove index.php
    # Uses the "include method"
    # http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method
    # 
    RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC]
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5})$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/(home|inc|publishers|sidebars|about|include-template|testing|advertisers|products|sitemap|style|ad-choices|social-bar|search|404||members|P[0-9]{2,8}) [NC]
    RewriteRule (.*) /index.php/$1 [L]

解决方案

This would remove query string from url

RewriteRule ^(.*) /index.php/$1? [L] #remove query string

Hope it helps

这篇关于的.htaccess URL重写挑战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆