Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

URL rewrite rule to to add final slash to folder name

Posted on 2009-07-12
8
Medium Priority
?
516 Views
Last Modified: 2013-12-25
Hi,

I want to redirect this url

www.mysite.com/search

 to mysite.com/search/

Just to add a final Slash at the end.

How to do this in the .htaccess ?
0
Comment
Question by:Fernanditos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 29

Expert Comment

by:Michael Worsham
ID: 24835600
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

Reference:
http://www.mydigitallife.info/2007/03/19/add-trailing-slash-to-the-end-of-the-url-with-htaccess-rewrite-rules/
0
 

Author Comment

by:Fernanditos
ID: 24835637
Hi, Thank you. I have problem with the order or position where to place it inside my file. Here I attach the content of my .htaccess so it better for you to help me.
<IfModule mod_security.c>
	# Turn off mod_security filtering.  
	SecFilterEngine Off
 
	# The below probably isn't needed, but better safe than sorry.
	SecFilterScanPOST Off
</IfModule>
 
<IfModule mod_deflate.c>
	AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/css text/ html text/xml
</IfModule>
 
RewriteEngine On
RewriteBase /
#Options +followsymlinks
RewriteEngine On
 
RewriteRule ^legal-terms-glossary/?$ /legal-glossary.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /legal-glossary-details.php?l=$1&id=$2&id_glo=$3 [L]
 
RewriteCond %{REQUEST_URI} !^/(search/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/?$ browse-by-state.php?id_subcat=$1 [L]
 
rewriterule ^([^-]+)-([^-]+)\.htm$ /categ-result.php?id_cat=$1&txt=$2 [L]
 
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ browse-by-city.php?id_subcat=$1&state=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ lawyers_result.php?id_subcat=$1&state=$2&city=$3 [L]
 
RewriteCond %{REQUEST_URI} !^/(categories/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)-([^/\.]+)\.html$ lawyer_details.php?state=$1&city=$2&id_lawyer=$4&id_law=$3 [L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Open in new window

0
 
LVL 7

Expert Comment

by:darrickhartman
ID: 24839039
You should only need ONE statement that says "ReWriteEngine On"  You have two listed.  Remove the second statement.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Fernanditos
ID: 24839151
Yes, I removed but where to place the code solution that mwecomputers gave me?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
<IfModule mod_security.c>
        # Turn off mod_security filtering.  
        SecFilterEngine Off
 
        # The below probably isn't needed, but better safe than sorry.
        SecFilterScanPOST Off
</IfModule>
 
<IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/css text/ html text/xml
</IfModule>
 
RewriteEngine On
 
RewriteRule ^legal-terms-glossary/?$ /legal-glossary.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /legal-glossary-details.php?l=$1&id=$2&id_glo=$3 [L]
 
RewriteCond %{REQUEST_URI} !^/(search/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/?$ browse-by-state.php?id_subcat=$1 [L]
 
rewriterule ^([^-]+)-([^-]+)\.htm$ /categ-result.php?id_cat=$1&txt=$2 [L]
 
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ browse-by-city.php?id_subcat=$1&state=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ lawyers_result.php?id_subcat=$1&state=$2&city=$3 [L]
 
RewriteCond %{REQUEST_URI} !^/(categories/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)-([^/\.]+)\.html$ lawyer_details.php?state=$1&city=$2&id_lawyer=$4&id_law=$3 [L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Open in new window

0
 
LVL 7

Expert Comment

by:darrickhartman
ID: 24875884
I would try inserting the code right after the "RewriteEngine On" line.  You will need to adapt his code snippet to fit for your site.  (ie change domain.com to the specific domain you are using).
0
 

Author Comment

by:Fernanditos
ID: 24899644
Notice that I only want to add end slash if is mydomain.com/seach

So, I do not want to add final slash to all.

Pls Help.
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 24962231
> Notice that I only want to add end slash if is mydomain.com/seach

In that case:
<IfModule mod_security.c>
        # Turn off mod_security filtering.  
        SecFilterEngine Off
 
        # The below probably isn't needed, but better safe than sorry.
        SecFilterScanPOST Off
</IfModule>
 
<IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/css text/ html text/xml
</IfModule>
 
RewriteEngine On
RewriteBase /
#Options +followsymlinks
 
RewriteRule ^search$ /search/ [R=301,L]
 
RewriteRule ^legal-terms-glossary/?$ /legal-glossary.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /legal-glossary-details.php?l=$1&id=$2&id_glo=$3 [L]
 
RewriteCond %{REQUEST_URI} !^/search/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/?$ browse-by-state.php?id_subcat=$1 [L]
 
RewriteRule ^([^-]+)-([^-]+)\.htm$ /categ-result.php?id_cat=$1&txt=$2 [L]
 
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ browse-by-city.php?id_subcat=$1&state=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ lawyers_result.php?id_subcat=$1&state=$2&city=$3 [L]
 
RewriteCond %{REQUEST_URI} !^/categories/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)-([^/\.]+)\.html$ lawyer_details.php?state=$1&city=$2&id_lawyer=$4&id_law=$3 [L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^  index.php [L]

Open in new window

0
 

Author Comment

by:Fernanditos
ID: 25423638
It works great. Thank you master !
0

Featured Post

When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot has fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question