简体   繁体   中英

how to keep htaccess file under site root

localhost, xampp, win 7
site path:
C:\\xampp\\htdocs\\news\\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 , ie view.php is loaded, but without images, css and js files (they are all under previous, ie 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM