Forum Moderators: phranque
i'm a noob in htaccess coding, so could you help me
i am trying to add a slash at the end of a given url.
how can i redirect url for example
[site.example.com...] to [site.example.com...]
also cms is a directory, so i need a rewrite rule, which indicates that if ther's no other characters it will redirect.
http://site.example.com/cms - Redirect
http://site.example.com/cms/asd - Don't redirect
my htaccess code is :
# Turn on URL rewriting
RewriteEngine On
RewriteBase /
# Protect application and system files from being viewed
RewriteRule ^(libs¦modules) - [F,L]
#here should be redirect
RewriteCond %{REQUEST_FILENAME} /cms$ [NC]
RewriteRule ^(.*)$ http://site.example.com/cms/ [R,L]
#redirect end
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite all other URLs to index.php/URL
RewriteRule .* /index.php?cms=1&url=$0 [PT,L]
Thanks
[edited by: jdMorgan at 2:37 pm (utc) on Jan. 22, 2010]
[edit reason] example.com [/edit]
# Turn on URL rewriting
RewriteEngine On
#
# Protect application and system files from being viewed
RewriteRule ^(libs¦modules) - [F]
#
# Externally redirect to add trailing slash to requests for "/cms"
RewriteRule ^cms$ http://site.example.com/cms/ [R=301,L]
#
# If not a request for index.php
RewriteCond $1 !^index\.php$
# RewriteCond $1 !(\.(gif¦jpe?g¦css¦js¦ico)¦^robots\.txt¦sitemap\.xml)$
# and if requested URL does not resolve to existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Internally rewrite to index.php/cms=1&url=<requested-URL-path>
RewriteRule ^(.*)$ /index.php?cms=1&url=$1 [PT,L]
Consider adding further exclusions to the final rule for robots.txt, sitemap.xml, any requested URL-path that ends with .gif, .jpg, .jpeg, .css, .js, or .ico, and any other frequently-requested objects which you *know* must (or should) exist on your server. Avoiding unnecessary file- and directory-exists checks will result in server speed improvements and less wear-and-tear on your hard drive. I show an example RewriteCond (currently commented-out) to exclude some of these objects.
Also consider adding canonicalization rules to redirect direct client requests for /index.php to "/", and to redirect non-canonical hostname requests to the canonical hostname (e.g. redirect non-www to www). If added, these rule should go after your trailing-slash redirect.
Jim
RewriteRule ^cms$ [site.example.com...] [R=301,L] works great, but it doesn't redirect when ther's
RewriteRule ^(.*)$ /index.php?cms=1&url=$1 [PT,L]
it sort of doesn't react to this line
<snip>
[edited by: jdMorgan at 5:33 pm (utc) on Jan. 22, 2010]
[edit reason] No URLS, please. See Terms of Service and Charter. [/edit]