skip to Main Content

When I created my latest website I made the foolish mistake of including Upper Case letters and underscores in the URLs. Although it’s a bit late (I have about 90 pages in the website) I would like to correct this now in the most orderly way possible.

Example: mydomain.com/DIR/Page_Name.php should become mydomain.com/dir/page-name.php.

What is the best way of doing this without slowing down the site or incurring SEO problems?

My first thought is to put a mod_rewrite line into .htaccess for every page and then rename that page. The downside to that is that there will be an extra 90 lines in the .htaccess file. But hopefully after a few months the search engines would have noticed and indexed everything with the new URLs and I could then remove all the stuff in .htaccess.

Am I talking sense? Are there any pitfalls I haven’t thought of? Is there a better way?

3

Answers


  1. Chosen as BEST ANSWER

    My solution was to rename the pages by creating a temporary php file and running that once for each page to do the renaming (tedious but not unreasonable with about 90 pages).

    Then I have added a line in the .htaccess file corresponding to each page, along the lines of

    redirect 301 /DIR/Page_Name.php https://example.com/dir/page-name.php
    

    Again, I was able to use a temporary php file to automate the creation of the text and avoid tedious typing.

    Finally I created a new sitemap and submitted it.

    While I appreciate this may not have been the best solution technically, it worked within the limits of my knowledge and avoided me venturing into areas like regex where I usually make a messs of things.


  2. Depending on how your application is constructed there are several different methods.

    The key thing to ensure you do is a 301 Permanent redirect which will tell search engines to forget your old page url and store your new url:
    https://en.wikipedia.org/wiki/HTTP_301

    Most search engines also have a method to submit a sitemap which you can use to tell them about major changes:
    https://support.google.com/webmasters/answer/183668?hl=en

    If you are using any sort of framework for your application you may be able to add some logic to perform this 301 redirect. However, this depends on your framework.

    Otherwise, as you’ve mentioned, you can write some rewrite rules with htaccess. You could write some regex checking for uppercase and rewriting to all lowercase.

    Login or Signup to reply.
  3. mod_speling may be helpful here; it can automatically correct case, assuming URLs correspond to the filesystem. (Underscores to hyphens would be considered a spelling mistake, so that particular correction will only work for files with one underscore.)

    You could also use RewriteMap, but that requires the RewriteMap directive to be placed in the server config file for some reason, so there probably isn’t much advantage over mod_speling.

    Or you could add some logic to your 404 page to check if the URL has uppercase letters and redirect if it does, or rewrite any URL with uppercase letters to a script that makes things lowercase.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search