How to make apache RewriteRule work correctly for a subdomain?

I just set up a subdomain with the following RewriteCond:

RewriteCond $1 !^search.php$  
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^/?([^/]+)$ search.php?q=$1 [L,NS] 

I use the same rewrite condition in my main domain and it works fine. However, when I install it on a subdomain, it simply displays "index.php" when going to http://sub.domain.com

Each subdomain page displays the page name in the body instead of processing the code, with the exception of the search page, which seems to work correctly.

What can I do to fix this problem?

+5
source share
4 answers

mod_rewrite, , . , , $ , ( $ , URI, , , )?

RewriteCond $1 !^search.php$  
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^/?([^\/]+)$ search.php?q=$1 [L,NS] 

. $ " , ". , RewriteCond ^ search.php $, URL- search.php? Q =..., , , search.php . , ( ).

RewriteCond $1 !^search.php
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^/?([^/]+)$ search.php?q=$1 [L,NS] 
+1

/, :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^search.php$                                                                                                                                                                             
RewriteCond %{REQUEST_FILENAME} !-f                                                                                                                                                                                       
RewriteRule ^/([^/]+)$ %{DOCUMENT_ROOT}/search.php?q=$1 [L]   

.htaccess RewriteBase, URL (/ ), .

RewriteEngine On
RewriteBase /                                                                                                                                                                                                             
RewriteCond %{REQUEST_FILENAME} !^search.php$                                                                                                                                                                             
RewriteCond %{REQUEST_FILENAME} !-f                                                                                                                                                                                       
RewriteRule ^([^/]+)$ search.php?q=$1 [L]   
+1

:

//gotchas. , :

  • , search.php $_GET. , .
  • RewriteRule , , .htaccess. , ^/ , URL (http://sub.domain.com/blah).
  • , , httpd.conf/apache2.conf .htaccess.
  • , RewriteEngine On, perc VirtualHost.
  • NS , Redirect RewriteRule.
0

, '^/? ([^/] +) $' .

RewriteLog, RewriteLogLevel 3 , . , , .

, - , "RewriteRule ^/? ([^/] +) $'. RewriteLog.

I believe that I recently had a problem where in some cases "^ /" did not match the virtual host. But the "/" worked. I was helped by people at #httpd on Freenode.org. If I find this in my notes, I will post it here.

0
source

All Articles