I have a project in a subfolder of my xampp root (rootFolder/myProjectName). Ok. But I'm using friendly URLs. So, whenever I want to link a JS or CSS file, for example, if I set:
<script type="text/javascript" src="/script.js"></script>
This is pointing to rootFolder/script.js not rootFolder/myProjectName/script.js!
Ok! I could add manually.. But, later, if I change my project to another folder or even to the root, I'd to change one by one!
How can I set the base folder of my project as "myProjectName" using htaccess (Or, if there is a better way..).
My htaccess is currently like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
This is because I'm using the "index.php" to route! But there are some pages called outside ( http://localhost/myProjectName/html/pageName ) and I cant get scripts to find their way without setting "[src="**myProjectName/**script.js"] manually!
You can done it with the next way with VirtualDocumentRoot
<VirtualHost *:80>
UseCanonicalName Off
VirtualDocumentRoot /path_to_rootFolder/%0
<Directory /path_to_rootFolder>
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /path_to_logs/error_log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
# LogLevel debug
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog "/path_to_logs/access_log" vcommon
Then add domain name to your hosts file eg "test.loc". Create test folder in your rootFolder and Apache will looks to test folder. Also when you will need new project you can create new folder with another name and add new domain for it into your hosts file. But you domain name and folder name should be the same.
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.