/ / .htaccess रूट URL को सबडायरेक्ट फ़ाइलों में रीडायरेक्ट करने के लिए, URL को क्लीन करने के लिए फिर से लिखें और सबडोमेन को प्रभावित न करें? - अपाचे, .htaccess

.htaccess रूट यूआरएल को उपनिर्देशिका फाइलों पर रीडायरेक्ट करने के लिए, यूआरएल को साफ करने के लिए फिर से लिखें और सबडोमेन को प्रभावित नहीं करें? - अपाचे, .htaccess

हेवन "मैं यहाँ .htaccess QA" में जो ढूंढ रहा हूँ वह मुझे नहीं मिल पाया है इसलिए यदि यह डुप्लिकेट है तो मुझे क्षमा करें। मुझे स्थिर HTML साइट के साथ निम्नलिखित समस्या है। संरचना नीचे है।

मेरे रिश्तेदार रास्ते में info.html तथा contact.html उपयोग करना है /home/css/style.css जबकि index.html का उपयोग करता है /css/style.css। मदद के लिए शुक्रिया।

Root
- .htaccess
↳ Drupal
- .git
↳ Dev
- .git
↳ Home
- .htaccess
- .git
- css
- js
- img
- info.html
- contact.html
- index.html

लक्ष्य

  • Dev.example.com से सभी फ़ाइलों का उपयोग करने के लिए /Dev
  • example.com से सभी फ़ाइलों का उपयोग करने के लिए example.com/home
  • example.com/info से पुनर्निर्देशित करना example.com/home/info.html.
  • example.com/contact से पुनर्निर्देशित करना example.com/home/contact.html.

मैंने अब तक क्या किया

जड़ में ।htaccess

      # Set a default home directory, (this subfolder always loads)
# RewriteEngine On
# RewriteCond %{THE_REQUEST} ^GET /home/
# # RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# RewriteRule ^home/(.*) /$1 [L,R=301]

# RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# RewriteRule !^home/ home%{REQUEST_URI} [L]

Options -Indexes

ErrorDocument 404 /missing.html

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

<FilesMatch ".(htm|html|css|js)$">
AddDefaultCharset utf-8
</FilesMatch>

RedirectMatch 404 "(?:.*)/(?:.git|file_or_dir)(?:/.*)?$"

# remove .html from html file names
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]

और रूट / ड्रुपल .htaccess में

default drupal stuff

निकटतम उत्तर मैं SO पर पा सकता हूं:


संपादित करें: मैं आंशिक रूप से, बाद में दी गई सलाह को समाप्त कर चुका हूं क्योंकि मेरे पास अलग-अलग git repos प्रति उपनिर्देशिका है। धन्यवाद @Jon Lin और @tttony!

नई समस्या: रूट। में मेरा .htaccess मुझे सबफ़ोल्डर में अपने ड्रुपल इंस्टॉलेशन को देखने नहीं देता है।

  • Drupal.examples.com से सभी ड्रुपल फ़ाइलों का उपयोग करता है /Drupal**

उत्तर:

जवाब के लिए 2 № 1

सबसे आसान काम है, अभी तक, सिर्फ बनाना है home आपके दस्तावेज़ रूट और एक उपनिर्देशिका होने के बारे में चिंता करने की ज़रूरत नहीं है।

लेकिन आपको जो काम करना है, उसके लिए सबसे पहली चीज जो आपको करनी है, वह है मार्ग सब कुछ सेवा मेरे /home और न सिर्फ / निवेदन:

RewriteEngine On
RewriteRule ^(.*)$ /home/$1 [L]

दूसरी बात, यह स्थिति:

RewriteCond %{REQUEST_FILENAME}.html -f

यदि आपके पास एक अनुगामी स्लेश है तो यह हमेशा विफल रहेगा, क्योंकि यह "इस तरह दिखने वाली फ़ाइलों की जाँच करने का प्रयास करेगा:"

/home/contact/.html

इसके बजाए इसे आजमाएं:

# remove .html from html file names
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/(.*)/$
RewriteCond %{DOCUMENT_ROOT}/home/%1.html -f
RewriteRule ^(.+)/$ $1.html [L]

जवाब के लिए 2 № 2

मेरे पास उप-फ़ोल्डर्स के साथ समस्या है, आप उपयोग करने का प्रयास कर सकते हैं RewriteBase आपके रूट में .htaccess

RewriteEngine On
RewriteBase /home/

लेकिन मैंने पाया कि रूट फ़ोल्डर में सिर्फ एक .htaccess फ़ाइल का उपयोग करना बेहतर है

# remove .html from html file names
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ %{REQUEST_URI} [L,R=301]
RewriteCond home/%{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ home/$1.html [L]