.htaccess影响文件中的其他URL

问题描述:

I have recently create the .htaccess to rewrite the url for SEO friendly. The url becomes working fine. But the url I assign will effect the url of other. The .htaccess file is shown in fig. When subject file runs. The url will be as class/physics When I click on any other file on subject page. Before changing url the login page url is login.php After changing the name of other file it also effects the login.php it appears like class/login.php which is annoying. Guide me to solve this problem.

<Files .htaccess>
order allow,deny
</Files>
Options +FollowSymLinks
RewriteEngine On 

#--exclude real directories
RewriteCond %{REQUEST_FILENAME} !-d
#--and files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\w+)/(\w+)$ ./subject.php?class=$1&subject=$2 [NC,L]

</div>

我最近创建.htaccess来重写SEO友好的网址。 网址变得很好。 但我分配的网址将影响其他网址。 .htaccess文件如图2所示。 主题文件运行时。 当我点击主题页面上的任何其他文件时,网址将作为类/物理。 在更改url之前,登录页面的URL是login.php更改其他文件的名称后,它也会影响login.php,它看起来像class / login.php,这很烦人。 指导我解决这个问题。 p>

\ r
 &lt; Files .htaccess&gt; 
 
order allow,  deny 
 
&lt; / Files&gt; 
 
Options + FollowSymLinks 
 
RewriteEngine On 
 
 
 
# - 排除真实目录
 
RewriteCond%{REQUEST_FILENAME}!-d 
 
#  --and files 
 
RewriteCond%{REQUEST_FILENAME}!-f 
 
RewriteRule ^(\ w +)/(\ w +)$ ./subject.php?class=$1&subject=$2 [NC,L]   pre> 
 
  div> 
 
  div> 
 
 
  div>

It looks like you have a problem with relative URLs. If on the /class/physics page (or URL) you have a relative link to login.php then this will naturally be relative to the /class/ "directory" (as it appears on the client-side), so the resulting URL is /class/login.php, not /login.php, which appears to be your intention.

Ideally, you need to make your URLs root-relative (starting with a slash) eg. /login.php. (Or even absolute, with a scheme + hostname.)

Alternatively, as workaround you can use the base element in the head section to inform user-agents what the relative URL is relative to. For example, if these URLs are intended to be relative to the document root then:

<base href="http://example.com/">

Note, however, there are some caveats with the base tag. Notably if you are using internal anchors eg. #top, then this is now relative to the base URL. (And this breaks on IE6 without a hack.)

Your old URLs (ie. /subject.php?class=abc&subject=abc) all appear to be in the document root, so your relative links were not a problem.