2010-05-04 10 views
12

नोट: मैंने this question के तहत सुझावों का प्रयास किया है, लेकिन वे या तो काम नहीं करते हैं या मुझे अनंत रीडायरेक्ट लूप त्रुटि देते हैं।रूट को फिर से लिखने के लिए Mod_Rewrite का उपयोग करें

मैं अपने .htaccess फ़ाइल में निम्नलिखित है:

<IfModule mod_rewrite.c> 

    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteBase/

    # Rewrite old links to new 
    Redirect 301 /howitworks.php  /how-it-works 
    Redirect 301 /testimonials.php  /testimonials 
    Redirect 301 /contact_us.php  /customer-service 
    Redirect 301 /affiliates.php  /affiliates 
    Redirect 301 /account.php   /customer/account 
    Redirect 301 /shopping_cart.php  /checkout/cart 
    Redirect 301 /products.php   /starter-kits 
    Redirect 301 /login.php    /customer/account/login 

    # Force to Admin if trying to access admin 
    RewriteCond %{HTTP_HOST} www\.example\.com [NC] 
    RewriteCond %{REQUEST_URI} admin [NC] 
    RewriteRule ^(.*)$ https://admin.example.com/index.php/admin [R=301,L,QSA] 

    # Compress, Combine and Cache Javascript/CSS 
    RewriteRule ^(index.php/)?minify/([^/]+)(/.*.(js|css))$ lib/minify/m.php?f=$3&d=$2 

    # Always send 404 on missing files in these folders 
    RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ 

    # Never rewrite for existing files, directories and links 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-l 
    RewriteCond %{REQUEST_URI} !server-status 

    # Rewrite everything else to index.php 
    RewriteRule .* index.php [L] 

    # Force www in url and non-example domains to example 
    RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] 
    RewriteCond %{HTTP_HOST} !^ww2\.example\.com [NC] 
    RewriteCond %{HTTP_HOST} !^qa\.example\.com [NC] 
    RewriteCond %{HTTP_HOST} !^uat\.example\.com [NC] 
    RewriteCond %{HTTP_HOST} !^local\.example\.com [NC] 
    RewriteCond %{HTTP_HOST} !^admin\.example\.com [NC] 
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L,QSA] 

</IfModule> 

मैं एक पुनर्लेखन कि निम्न करेगा की जरूरत है:

पुनर्लेखन: http://subdomain.example.com/कोhttp://subdomain.example.com/page

मैं भी चाहते हैं यह/पृष्ठ को छिपाने के लिए (/ जैसा कि यह था/पृष्ठ होगा) लेकिन यह एक आवश्यक आवश्यकता नहीं है। इसके अलावा, मैं इसे HTTP या HTTPS के साथ काम करना चाहता हूं।

किसी भी मदद की बहुत सराहना की जाती है क्योंकि मैं घंटों तक इसके साथ संघर्ष कर रहा हूं।

+1

यह सवाल ServerFault पर अंतर्गत आता है। – leek

उत्तर

20

रूट पथ का एक सही रीडायरेक्ट बस है:

RewriteEngine On 
RewriteRule ^/$ /page [R] 

केवल एक उप डोमेन पर इस के लिए मजबूर करने (जो मुश्किल से अगर आपका रीराइट ब्लॉक एक वर्चुअलहोस्ट परिभाषा है होना चाहिए):

RewriteEngine on 
RewriteCond %{HTTP_HOST} =subdomain.example.com 
RewriteRule ^/$ /page [R] 
+5

यह उत्तर बस htaccess संदर्भ में काम नहीं करता है, और क्लाइंट को पूर्ण रीडायरेक्ट करता है (IOW "पूछे जाने वाले" छिपे नहीं हैं) – covener

+4

यह केवल^$ के बजाय ^/$ का उपयोग करने के बाद यह केवल apache2 पर मेरे लिए काम करता है। क्या जवाब गलत है या क्या मैं गलती कर रहा हूं? –

+0

गलत: रिवाइटरूल^$/पेज [आर] दाएं: रिवाइट्रूल ^/$/पेज [आर] – Hartmut

5

अपना हटाया प्रतिक्रिया को कॉपी करना:

बस अपने DocumentRoot की htaccess में:

RewriteEngine on 
RewriteCond %{HTTP_HOST} =subdomain.example.com 
RewriteRule ^$ /page 
+1

यह सुनिश्चित नहीं है कि यह क्यों हटा दिया गया है ... 'रिवाइटरूल^$/पेज' एकमात्र वैध उत्तर प्रतीत होता है। 'RewriteRule ^/$/page' _NOT_ साइट के दस्तावेज़ रूट के अनुरोध से मेल खाता है।मैं वर्तमान में स्वीकृत उत्तर को संशोधित कर रहा हूं ताकि यह सही हो। – joshperry

1

आप किसी अन्य पथ के लिए अपने रूट के पुनर्लेखन के लिए 2 विकल्प हैं,

1) DirectoryIndex

DirectoryIndex anotherPath 

2) मॉड-रीराइट:

RewriteEngine on 


RewriteRule ^/?$ /anotherPath [L] 

आप उपयोग कर सकते हैं आंतरिक रूप से रीडायरेक्ट करने के लिए उपरोक्त विकल्पों में से example.com/ से उदाहरण.com/anotherPath

refrences:

https://httpd.apache.org/docs/current/mod/mod_dir.html

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

संबंधित मुद्दे