url到新格式

时间:2011-04-05 08:41:34

标签: apache .htaccess mod-rewrite url-rewriting

以下是我的.htaccess文件。它不适用于localhost apache(www是C:/ apache / www上的根目录)“url”是目录,我想要这样的输出

http://localhost/url/index.php?username=shahhttp://localhost/url/shah

我更改了Windows主机文件127.0.0.1 localhost &安培;还在httpd.conf文件中启用mod_rewrite& AllowOverride none to AllowOverride All &安培;根目录到C:/ apache / www

//==============================HTaccess==================================//
 Options:
# -MultiViews: Turns off multiviews so it doesn't interfer with our rewrite rules
# -Indexes: Stop directory listings
# +FollowSymlinks: Let out rewrite rules work

Options -MultiViews -Indexes +FollowSymlinks

<IfModule mod_security.c>
    # Turn off mod_security filtering.
    # SecFilterEngine Off

    # The below probably isn't needed, but better safe than sorry.
    SecFilterScanPOST Off
</IfModule>

ErrorDocument 404 /url/404.php

<IfModule mod_php5.c>
    php_value register_globals 0
    php_value magic_quotes_gpc 0
    php_value session.auto_start 0
    php_value safe_mode 0
</IfModule>

<IfModule sapi_apache2.c>
    php_value register_globals 0
    php_value magic_quotes_gpc 0
    php_value session.auto_start 0
    php_value safe_mode 0
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /url/
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?username=$1

#RewriteRule ^view-content/([^/]*)/([^/]*)\.html$ content.php?pageid=$1&title=$2 [L]

</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>
//==============================HTaccess==================================//

请告诉我该怎么做?

2 个答案:

答案 0 :(得分:0)

试试这个:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /url/
RewriteCond %{QUERY_STRING} username\=(.*)
RewriteRule index\.php$ /url/%1

希望这有助于你...... :)

答案 1 :(得分:0)

如果您确实要将/url/index.php?username=shah的请求从外部重定向到/url/shah,请尝试以下规则:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*?)username=([^&]+)&*(.*)
RewriteRule ^index\.php$ /url/%3?%1%4 [L,R=301]

否则,反方向:

RewriteCond $0 !=index.php
RewriteRule ^[^/]+$ index.php?username=$0 [L,QSA]