简体   繁体   English

HTAccess URL重写影响GET变量

[英]HTAccess URL Rewrite affect GET variables

We're using wordpress, and we have the following in the .htaccess: 我们正在使用wordpress,并且.htaccess中包含以下内容:

# BEGIN WordPress

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

# END WordPress

We have a URL like http://subdomain.example.com/select-a-card/?q=fuel , and we want to rewrite it so that it becomes something like http://subdomain.example.com/fuel-card/ 我们有一个类似http://subdomain.example.com/select-a-card/?q=fuel的URL,我们想重写它,使其变成类似于http://subdomain.example.com/fuel-卡/

What do I need to add to the htaccess to do this? 我需要在htaccess中添加什么才能执行此操作? Also, will this affect the queries from running that uses GET variables? 另外,这是否会影响使用GET变量运行的查询?

nothing, just read the wordpress manual and edit your settings. 没什么,只需阅读wordpress手册并编辑设置即可。 checkout http://codex.wordpress.org/Using_Permalinks 结帐http://codex.wordpress.org/Using_Permalinks

--- EDIT -编辑

This can be done, but only if you have some sort of a standard markup of the url's you want to have rewritten. 可以做到这一点,但前提是您要重写某种形式的url标准标记。 Ie. 就是 if you only want to rewrite the select-a-card url's, or only the url's with a syntax like http://site.com/uri/?q=something . 如果您只想重写选择卡片的网址,或者仅重写具有类似http://site.com/uri/?q=something的语法的网址 But you if the syntax of the url's differ too much you will have to add a lot of rewrites. 但是,如果url的语法差异太大,则必须添加大量重写。

In this specific case something like this should work: 在这种特定情况下,应执行以下操作:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # add your specifics below:
    RewriteRule ^/select-a-card/\?q=(.*) $1-card/

    RewriteRule . /index.php [L]
</IfModule>

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

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