2012-08-10 102 views
0

我已经看过每个问题和每个Apache的服务器reWriteRule的例子......没有任何工作。mod_rewrite干净的URL不工作

我只需要改变 http://beta.EXAMPLE.com/profile.php?profile_name=ntgCleanerhttp://beta.EXAMPLE.com/ntgCleaner

我必须看到,如果my .htaccess file is being read,并查看if mod_rewrite is enabled,他们都完全正常工作。

出于某种原因,我遇到的例子不适合我。以下是一些例子。

RewriteEngine On 
RewriteRule /(.*)$ /profile.php?username=$1 

RewriteEngine On 
RewriteBase/
RewriteRule ^profile\/(.*)$ ./profile.php?profileId=$1 [L,NC,QSA] 

Options +FollowSymlinks 
RewriteEngine on 
RewriteOptions MaxRedirects=10 
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?profile_name=$1 
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?profile_name=$1 

但所有这些工作。这是因为我使用的是一个子域吗?我计划在完成网站时最终将BETA中的子域名切换到www。

有什么建议吗?

回答

1

试试这个:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /profile.php?profile_name=$1 [L,QSA] 

你的例子有很多不同的是查询字符串的,所以我不知道哪一个是你真正想要的。您有?username=,?profileId=,?profile_name=

+0

噢,对不起,我只是希望它使用PROFILE_NAME作为清洁网址,所以从example.com/ profile.php?profile_name = ntgCleaner to example.com/ntgCleaner 那些我们只是我想要的例子 – ntgCleaner 2012-08-10 18:28:32

+0

这正是我需要的!我不认为request_filename必须处理任何事情......谢谢! – ntgCleaner 2012-08-10 18:30:56

+1

@ntgCleaner这是一种不会无限循环的方式,因为如果URI指向现有资源(如profile.php),它将不会重新重写。 – 2012-08-10 18:33:46

0

您必须使用条件(RewriteCond),当条件满足时,应用规则(RewriteRule)。所以,当你不使用条件时,不会使用规则,因为引擎不知道该使用什么。

的RewriteCond重写规则必须之前使用,我以这种形式用它对付网络机器人:

RewriteCond %{REMOTE_HOST} .googlebot.com$ [NC,OR] 
RewriteCond %{REMOTE_HOST} .search.msn.com$ [NC,OR] 
RewriteCond %{REMOTE_HOST} .kimsufi.com$ [NC] 
RewriteRule ^.*$ /errors/404.html [F] 
+0

伟大的信息,谢谢你为我清除drobik! – ntgCleaner 2012-08-10 18:39:09