1

我对 .htaccess 和 mod_rewrite 很陌生。我可以准备带有特定网址的 seo 友好网址。但是,我想制作一个为我统一一切的东西。

例如;

Original : http://www.domain.com/index.php?module=profile&id=1.
SEO : http://www.domain.com/profile/1
.htaccess Code: RewriteRule ^profile/(.*)  ?module=profile&id=$1 [L]

如您所见,我必须在文件中指定profile任何其他模块名称.htaccess

我想做的是;

Original : http://www.domain.com/?request=module/profile/id/1/other/any
SEO : http://www.domain.com/module/profile/id/1/other/any

然而 mod_rewrite 的相同逻辑并不适用。

RewriteRule ^(.*)  ?request=$1 [L]

反正有这个问题吗?

我完整的.htaccess;

# Disable server signature
ServerSignature Off
####################################################################
# MOD REWRITE
####################################################################
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteRule (.*)  /index.php?request=$1 [L]

</IfModule>

我可以毫无问题地使用它;

# Disable server signature
ServerSignature Off
####################################################################
# MOD REWRITE
####################################################################
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteRule ^/ index.php [L]

RewriteRule ^content/(.*) ?module=content&request=$1
</IfModule>

工作版

# Disable server signature
ServerSignature Off
####################################################################
# MOD REWRITE
####################################################################
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteBase /

RewriteRule (.*) index.php?request=$1 [L]
</IfModule>

但是我仍然需要至少指定一件事。

感谢您的帮助。

4

1 回答 1

3

我认为您的方法没有任何问题,您只需要一个小修复:

编辑 2

RewriteRule (.*)  index.php?request=$1 [L]

就是这样。顺便提一句。您不妨将所有内容重定向到index.php并在超全局中查找请求参数$_SERVER['REQUEST_URI']

编辑

问题出在这里:

<IfModule mod_deflate.c>        <<<<<
SetOutputFilter DEFLATE
# Don't compress
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
#Dealing with proxy servers
<IfModule mod_headers.c>        <<<<<
Header append Vary User-Agent
</IfModule>
</IfModule>                     <<<<<

编辑 3

...
RewriteEngine on

# Pass any request not referring directly to a file or directory in the
# filesystem to index.php    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?request=$1 [L]
于 2012-11-02T15:49:58.793 回答