2011-04-05 86 views
0

下面給出的是我的.htaccess文件。它不工作在本地主機上的Apache(www是在C盤根目錄:/阿帕奇/ WWW)「網址」是目錄,我想這樣的新格式的網址

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

更改Windows主機文件127.0輸出.0.1本地主機 &也使mod_rewrite的在httpd.conf文件&的AllowOverride無人的AllowOverride所有 &根目錄爲C:/阿帕奇/ 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==================================// 

請告訴我該怎麼做?

+0

你能解釋一下哪些工作不正常嗎?它只是RewriteRule還是整個.htaccess文件被忽略? – clmarquart 2011-04-05 12:56:07

+0

請看下面的回答 – user692487 2011-04-06 06:08:07

回答

0

試試這個:

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

希望這有助於你... :)

+0

上面的例子重定向到找不到頁面 – user692487 2011-04-06 06:07:02

+0

你能告訴我它重定向了哪個url嗎? – 2011-04-06 07:01:42

+0

http://phpprojects.netau.net/url/index.php?username=hereusername – user692487 2011-04-06 08:03:52

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] 
+0

謝謝,您的代碼正在工作,但頁面未找到其本地更改的網址並顯示未找到網頁。在線phpprojects.netau.net/url/index.php?username=hereusername沒有顯示只有querystring – user692487 2011-04-06 09:06:03

+0

我的代碼是工作index.php?username = shah&現在我想知道關於這個問題RewriteRule^view-content /([爲什麼這不起作用 – user692487 2011-04-07 12:29:14

+0

我解決了它。感謝您的幫助。 – user692487 2011-04-17 05:16:05