1

現在、MAMP でローカルホストを使用しています。.htaccess ファイルの URL の書き換えを許可する適切な方法を読んで調査し、成功しました。しかし、現在、ファイルはリンクを希望どおりにフォーマットしていません。たとえば、 と の 3 つのページindex.phpabout.phpありcontactます。サイトのフレーム作業に MVC を使用しています。これは、.htaccess ファイルまたはローカル サーバーのコードに問題がありますか?

現在、あるページから別のページに移動する場合、リンクは次のようになります。

localhost/mvc/index.php?

localhost/mvc/index.php?p=about

localhost/mvc/index.php?p=contact

.htaccess は、リンクを次のようにフォーマットする必要があります。

localhost/mvc/index/?

localhost/mvc/about/?

localhost/mvc/contact/?

.htaccess:

<IfModule mod_rewrite.c>

# Turn on the engine:
RewriteEngine on

# Set the base to this directory:
RewriteBase /mvc/

# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1

</IfModule>
4

2 に答える 2

2

既存の .htaccess コードを次のコードに完全に置き換えます。

Options +FollowSymLinks -MultiViews

DirectoryIndex index.php index.html

# Turn mod_rewrite on
RewriteEngine On
# Set the base to this directory:
RewriteBase /mvc/

# Redirect /mvc/index.php?p=page to /mvc/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mvc/index\.php\?p=([^\s]+) [NC]
RewriteRule ^ %1/? [R=302,L]

# Redirect /mvc/index.php to /mvc/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+mvc/index\.php\s [NC]
RewriteRule ^ /mvc/ [R=302,L]

# Internally forward certain /mvc/page/ to /mvc/index.php?p=page
RewriteRule ^(about|contact|this|that|search)/?$ /mvc/index.php?p=$1 [L,QSA,NC]
于 2013-07-20T06:37:05.930 に答える
0

交換

RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1

と :

RewriteRule ^(about|contact|this|that|search)/\?$ index.php?p=$1

? をエスケープしただけです。そうしないと、疑問符が解釈され、その前のスラッシュがオプションであることを意味します。

于 2013-07-20T05:15:29.427 に答える