0

私の最初の質問は「urlパラメータの書き換えにjavascriptでパラメータを扱うことができますか?htmlとjavascriptで1つのファイルにhtaccessを使用してURLを書き直す

と2番目の質問は次のとおりです。これらのURLに

*localhost OR sample.com*/blog.html 
*localhost OR sample.com*/about.html 
*localhost OR sample.com*/articles.html?title=sample-name-parameter 

*localhost or sample.com*/blog/ 
*localhost or sample.com*/about/ 
*localhost or sample.com*/articles/sample-name-parameter 

はここに私のhtaccessファイルです 私はこれらのURLを書き換えたい場合は、私が?何をすべきか:

DirectoryIndex blog.html index.html 

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/$ $1.html 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^articles/([^/]+)$ /articles/$1.html?p=$2 [L] 
</IfModule> 

答えて

0

実際には、現在のパスを分割して、window.location.pathnameの現在のパスを使用してsplitを使用して、ピース内のパスを分割することはできません。

var path = window.location.pathname, // "/article/something" 
    peaces = path.split(), 
    title = peaces[1]; // "something" 

そして、このhtaccessのコード試してください:

DirectoryIndex blog.html index.html 

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^([^/]+)/$ $1.html 
RewriteRule ^articles/([^/]+)$ /articles/articles.html?title=$1 [L] 
</IfModule> 
+0

を実際に私は前にそれを試してみましたが、それはすべての Apacheサーバのショーでこのエラーは動作しませんでした:「要求されたURLの/articles/articles.htmlをこのサーバーには見つかりませんでした。" – Peedes

+0

articleフォルダ内のarticle.htmlファイルが見つからない場合は、単にhtaccessコードから 'RewriteRule^articles /([^ /] +)$ /articles/articles.html?title=$1 [L]'行を削除してください。ファイルルートに位置する –

関連する問題