2017-02-02 3 views
0

特定のURLからhtaccessファイルを使用して拡張子.phpを削除し、私が書いたルールは以下のとおりです。私は正常に動作している.htaccessファイル内のいくつかのルールを書いた

# browser requests PHP 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s/+(\S+?)\.php(/\S*)?\sHTTP [NC] 
RewriteRule^/%1%2 [L,R=301,NE] 

# check to see if the request is for a PHP file: 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^/?(.+?)(/.*)?$ /$1.php$2 [L] 

問題:私は彼らと持っている唯一の問題はということですその結果、私のAjaxリクエストが継続的に取得されているため、各URLから.php拡張子を削除しています。

:だから今の代わりに、すべてのファイルから拡張子.phpを除去する私から特に拡張子.phpを削除したいボタンの上にAjax呼び出しをAjax/x.phpのようなURLに作られているが、理由は上記のルールでそれがAjax/xに変換され、404

を返します2つのファイル、すなわちa.phpb.php

コミュニティと少しの助けが必要、私はほとんどthere.Any助けよ知っているあなたはこれを使用することができ、2つの特定のファイルから拡張子.phpを削除するには

答えて

1

を理解されるであろう。

RewriteCond %{THE_REQUEST} /(a|b)\.php [NC] 
RewriteRule^/%1 [L,R] 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*?)/?$ /$1.php [L] 
0
First of all, when you remove the php extension from any url, you have to submit the form by changing removing the .php extension from the action such as 
<form class="form-horizontal" method="post" action="new_team" enctype="multipart/form-data"> 
Same thing also will apply to the ajax file such as 
$.ajax({ 
      url: 'php/contact_form_submit', 
      type: 'post' 

.htaccess should look like this 
Options +MultiViews 
RewriteEngine On 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) 
RewriteRule^/%1 [R=301,L] 

# Unless directory, remove trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
# RewriteRule ^([^/]+)/$ http://url/$1 [R=301,L] 
RewriteRule ^([^/]+)/$ http://url/$1 [R=301,L] 

# Redirect external .php requests to extensionless url 
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ 
# RewriteRule ^(.+)\.php$ http://url/$1 [R=301,L] 
RewriteRule ^(.+)\.php$ http://url/$1 [R=301,L] 

# Resolve .php file for extensionless php urls 
RewriteRule ^([^/.]+)$ $1.php [L] 

so try it out and let me know if it solved 
関連する問題