I’m new to learning HTACCESS and I’m trying my best to work on a websites URLs to make them more “seo friendly” and load properly. I’ve tried searching all over for what I need to point me in the right direction, but everything seems to be for “wordpress” and this is a custom built site.
Here is my issue. This site had a previous developer, the thing was a mess, and I’ve spent countless hours cleaning up the site, and he built the sites to show urls like this. “www.sitename.com/about-us.php”
I’m familiar enough with htaccess to know how to remove the trailing extension for .php, even showing trailing variables properly that doesn’t require the trailing slash at the end like: “sitename.com/about-us?contact=true”
I was able to get the blog view page to load with a url like this: “sitename.com/posts/post-name-here/”. This one though does require the trailing slash.
What I’m trying to accomplish is making the url string to work properly with trailing variables for a few pages like, register, apply, etc. So those urls would be something like this. “sitename.com/auth/apply” or “sitename.com/auth/register”
My issue is that the urls have to have a trailing slash at the end or it doesn’t load.
Plus adding a trailing variables only works when formatted like this: “sitename.com/auth/apply/?application=submitted”
I’d prefer it look more like this. “sitename.com/auth/apply?application=submitted”, without the trailing slash. But I can’t find how to accomplish this.
Here is my .htaccess snippet.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^posts/(.*)/$ /view-post.php?post=$1 [QSA,NC,L]
RewriteRule ^auth/(.*)/$ /auth-action.php?action=$1 [QSA,NC,L]
RewriteRule ^([^.]+)$ $1.php [NC,L]
Can someone help me, or point me in the right direction?
2
Answers
Try using the following in your
.htaccess
. This will remove the trailing slash from your URLs.Make sure you clear your cache before testing this. You’ll notice that I’ve set
R=302
instead of301
. This makes it a temporary redirect for testing purposes. If you’re happy with the redirect then change it to301
to make it permanent.This should be what you’re looking for.