dsn1327
dsn1327
2017-06-22 05:03

如何在网站root下保留htaccess文件

已采纳

localhost, xampp, win 7
site path:
C:\xampp\htdocs ews\s02

so all relevant files, including .htaccess is under s02 folder.

links like this work fine:
http://localhost/news/s02/view.php?art=160915142500&title=blue-sky

I want the following computed url
http://localhost/articles/160915142500/blue-sky

.htaccess

RewriteEngine on
RewriteBase /
RewriteRule ^articles/([0-9]+)/([a-zA-Z-_]*)$ view.php?art=$1&title=$2 [NC,L]

result - error 404

httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so - uncommented
AllowOverride All - all instances

When I move .htaccess file to:
C:\xampp\htdocs
and change RewriteRule to:
RewriteRule ^articles/([0-9]+)/([a-zA-Z-_]*)$ news/s02/view.php?art=$1&title=$2 [NC,L]

there is no error 404, i.e. view.php is loaded, but without images, css and js files (they are all under previous, i.e. s02 folder.

How to keep .htaccess file under site root (s02) and load view.php with all its elements?

restarting xampp and apache and mysql modules doesn't help.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doujiao2014 doujiao2014 4年前

    I don't think this is possible to do from a sub directory. You are basically trying to rewrite a request sent to the root directory from within a sub directory. In order to rewrite the current url, apache should see the .htaccess file in the current directory.

    However you can still redirect to the specified location, but you have to make the .htaccess file in the htdocs directory.

    This is my first answer :) Not sure if this is suitable as an answer.

    点赞 评论 复制链接分享