php - Remove extension and force trailing slash to non trailing slash at end -


hi have website in using rules make urls seo friendly. here code :

options +followsymlinks     options -multiviews     rewriteengine on rewritecond %{http_user_agent} libwww-perl.*  rewriterule .* ? [f,l]  rewriterule ^([a-za-z0-9_-\s]+)/([a-za-z0-9_-\s]+)/([0-9]+)/([a-za-z0-9_-\s]+)$ /page1.php?var1=$1&var2=$2&var3=$3&var4=$4 [l,qsa] rewriterule ^([a-za-z0-9_-\s]+)/([a-za-z0-9_-\s]+)/([a-za-z0-9_-\s]+)$ /page2.php?var1=$1&var2=$2&var3=$3 [l] rewriterule ^([a-za-z0-9_-\s]+)/([a-za-z0-9_-\s]+)$ /page2.php?var1=$1&var2=$2 [l,qsa] rewriterule ^([a-za-z0-9_-\s]+)$ /page2.php?var1=$1 [l,qsa]  # remove trailing slash rewritecond %{request_filename} !-d rewritecond %{the_request} \s(.+?)/+[?\s] rewriterule ^(.+?)/$ /$1 [r=301,l]  rewritecond %{script_filename} !-d rewriterule ^([^\.]+)$ $1.php [nc,l]  errordocument 404 /404.php 

it working fine in cases in cases showing errors.

errors getting:

1) suppose have page3.php when go www.example.com/page3.php shows content of page3 without removing extension url when type www.example.com/page3 takes page3 variable , shows content of page2 have described rewrite rule single variable page2.

2) if write url www.example.com/var1/ rewrite url www.example.com/var1/.php if write www.example.com/var1/var2/ working fine i.e. removing traling slash.

as mentioned in error 1 first want redirect .php pages without php , second if in url www.example.com/page3 page3 file in root directory show content of page3 , if page3 not file in root directory should take page3 variable , should work rewrite rule mentioned above.

for error 2 want remove trailing slash url whether has 1 variable or 2 or 3 or 4 variables.

please me out...thanks in advance...

note: running website on https not on http.

  1. have redirect rules before rewrite one.
  2. before adding .php extension in .htaccess, check presence of corresponding .php file.

have this:

errordocument 404 /404.php options +followsymlinks -multiviews rewriteengine on  rewritecond %{http_user_agent} libwww-perl.*  rewriterule ^ - [f,l]  # remove trailing slash rewritecond %{request_filename} !-d rewriterule ^(.+)/$ /$1 [ne,r=301,l]  # skip files , directories rules below rewritecond %{script_filename} -d [or] rewritecond %{script_filename} -f rewriterule ^ - [l]  rewritecond %{request_filename}.php -f rewriterule ^([^.]+?)/?$ $1.php [nc,l]  rewriterule ^([\w-]+)/([\w-]+)/([0-9]+)/([\w-]+)$ page1.php?var1=$1&var2=$2&var3=$3&var4=$4 [l,qsa]  rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)$ page2.php?var1=$1&var2=$2&var3=$3 [l,qsa]  rewriterule ^([\w-]+)/([\w-]+)$ page2.php?var1=$1&var2=$2 [l,qsa]  rewriterule ^([\w-]+)$ page2.php?var1=$1 [l,qsa] 

test after clearing browser cache fully.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -