drbfxb977777 2017-05-04 10:00
浏览 27
已采纳

.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>
  • 写回答

1条回答 默认 最新

  • dongweihuan8832 2017-05-04 13:08
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM