2017-05-19 146 views
0

下面的代碼是針對特定於幾個頁面的根文件夾來刪除擴展名。它的工作。.htaccess在子文件夾中刪除擴展名不起作用

RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-l 

    RewriteRule ^About+$ about.php 
    RewriteRule ^FAQ+$ faq.php 
    RewriteRule ^Contact+$ contact.php 
    RewriteRule ^Gallery+$ gallery.php 
    RewriteRule ^Areas-we-service+$ cities.php 


    RewriteRule ^(([^/]+/)*[^.]+)$ servicesparse.php?name=$1 

然後我添加了一個名爲product的子文件夾。 路徑是根文件夾/ p​​hp-product-catalog-module。插件中有另一個htaccess文件。

#Fix Rewrite 
Options -Multiviews 

# Mod Rewrite 
Options +FollowSymLinks 
RewriteEngine On 
RewriteBase /php-product-catalog-module/ 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# used for viewing single product page 
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\/?$ product.php?name=$1&id=$2 

# used for php pages such as "yoursite.com/login.php" will become "yoursite.com/login/" 
RewriteRule ^([a-z_]+)\/?$ $1.php [NC] 

因此,子文件夾的htaccess不起作用。 它不會重定向http://cp2.designnrank.com/~wolverin/php-product-catalog-module/login.phphttp://cp2.designnrank.com/~wolverin/php-product-catalog-module/login

產品其他頁面的規則不起作用。

回答

0

你確定htaccess已啓用嗎?由於性能問題,現在在Apache中默認禁用htaccess文件。啓用.htaccess文件時,Web服務器必須在其所在位置的每個子目錄中檢查每個命中。

啓用htaccess可以通過在<Directory></Directory>指令中將「AllowOverride None」替換爲「AllowOverride All」來完成。

<Directory /var/www/> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Require all granted 
</Directory> 

更好的方法是將所有重寫規則放入虛擬主機配置文件中。例如:

<VirtualHost *:80> 

    DocumentRoot /var/www/mywebsite 

    ErrorLog ${APACHE_LOG_DIR}/mywebsite-error.log 
    CustomLog ${APACHE_LOG_DIR}/mywebsite-access.log combined 

    #Fix Rewrite 
    Options -Multiviews 

    # Mod Rewrite 
    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteBase /php-product-catalog-module/ 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    # used for viewing single product page 
    RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\/?$ product.php?name=$1&id=$2 

    # used for php pages such as "yoursite.com/login.php" will become "yoursite.com/login/" 
    RewriteRule ^([a-z_]+)\/?$ $1.php [NC] 

</VirtualHost> 
相關問題