2016-09-14 8 views
0

私のubuntuコンピュータにテスト用のウェブサイトがあります。URLはmysite.testです。 http://mysite.test/goodbye.phphttp://mysite.test/hello.phpなど.htaccessの.php拡張子を削除します。

は、私はまた、ワイルドカードのサブドメインがあります:私はマーケティングのページを持っているhttp://user1.mysite.test/page1.phphttp://user2.mysite.test/page.1phpなど

私は「.phpの」拡張(マーケティングを追加することなく、すべてのページにアクセスになりたいのサイト、サブドメイン)。私は.htaccessファイルを変更しましたが、動作していないため、理由を特定できません。 mod_rewriteが有効になっていて、動作しています(下記の "Remove www"ルールが機能します)。

#/var/www/mysite.test/public_html/.htaccess 
RewriteEngine On 
#Remove www - this works 
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC] 

#Not need .php extension - this does not work 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ $1.php 

最初のルール(「wwwを削除する」)を削除しても機能しなくなります。

私はhttp://mysite.test/helloに行くとき、私は404 Not Foundエラーを取得します。 http://mysite.test/hello.phpに行くだけで問題ありません。

私はhttp://user1.mysite.test/page1に行くとき、私は404 Not Foundエラーを取得します。 http://user1.mysite.test/page1.phpに行くだけで問題ありません。

私の仮想ホストファイルは以下のようになります。私は何をしないのです

#/etc/apache2/sites-available/mysite.test.conf 
<VirtualHost *:80> 
    ServerName www.mysite.test 
    ServerAlias mysite.test 
    ServerAdmin [email protected] 
    DocumentRoot /var/www/mysite.test/public_html 

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

    <Directory /var/www/mysite.test> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Order allow,deny 
      allow from all 
    </Directory> 
</VirtualHost> 

<VirtualHost *:80> 
    ServerName wildcard.mysite.test 
    ServerAlias *.mysite.test 
    DocumentRoot /var/www/mysite.test/public_html/app 

    <Directory /var/www/mysite.test/public_html/app> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride All 
      Order allow,deny 
      allow from all 
    </Directory> 
</VirtualHost> 

?ありがとうございました。

+0

''あなたは 'foo/bar/baz.php'に書き直すでしょう。 eディレクトリは存在しますか? –

+0

@ marc-b '' RewriteCond%{REQUEST_FILENAME}!-d''を.htaccessファイルに追加しましたが、それでも動作しません。 –

答えて

0

私は私はあなたの問題に役立つソリューションを与えることができわからないんだけど、私は動作するコードの同様の部分を持っている:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.|/]+)$ $1.php [NC,L] 

これはファイルでない場合ことを設定し、場合それは、それがファイル名に追加.phpを持っている(例えば画像reference.jpgなど.が含まれていません。

これは私のために完璧に動作します。誰かが `/ fooの/バー/バズであなたのサイトにヒットしたらどうなりますか

関連する問題