Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 160509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:02:51+00:00 2026-05-11T11:02:51+00:00

This is what I’m trying to do with the htaccess: Force remove the www

  • 0

This is what I’m trying to do with the htaccess:

  • Force remove the www from the url
  • Be able to use http://website.com/site/ to get to http://website.com/site.php, and force the last slash even if it’s not added by the user. So if i write http://website.com/site it will be converted to http://website.com/site/
  • Also translate http://website.com/download.php?=file.exe to http://website.com/download/file.exe. Also http://website.com/news.php?article=43532 into http://website.com/news/article/43532

The htaccess code should not have to contain the domain it’s going to be used on.

I’ve been trying to find something like this on the net for ages, but I only find each part and they don’t work together.

Can anyone help me with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:02:52+00:00Added an answer on May 11, 2026 at 11:02 am

    Ok, here’s my try. Note that the Apache manual is quite good. I differ from benlumley on the ‘site’ portion. Also, you may want to replace ([0-9]+) with simply (.+) if your news article names are not all numeric.

    # Ensure that rewriting is enabled RewriteEngine on  # First strip the www as benlumley did RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L]  # Then convert /site to /site/, reflecting the change in the address bar RewriteRule ^([^/.]+)$ /$1/ [R=301,L] # Finally map /site/ to /site.php RewriteRule ^([^/.]+)/$ /$1.php  # Finally, fix download and news as benlumley did RewriteRule ^download/(.+)$ /download.php?file=$1 RewriteRule ^news/article/([0-9]+)$ /news.php?article=$1 

    EDIT: Fixed copy/paste error for the ‘strip www’ part.

    NOTE: Any <link href='...'> or <script src='...'> tags that you have will now need to be specified as absolute paths because you have effectively changed the directory that the page appears to be served from.

    E.g. consider the following line from your blog.php:

    <link rel='stylesheet' type='text/css' href='style.css'> 

    Previously the browser saw http://site/blog.php and thus tried to retrieve http://site/style.css, which worked.

    Now that the browser instead sees http://site/blog/ the relative URL above is interpreted as http://site/blog/style.css, which does not exist. As such, the href needs to be changed as:

    <link rel='stylesheet' type='text/css' href='/style.css'> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have had issues like this that came down to… May 12, 2026 at 1:01 am
  • Editorial Team
    Editorial Team added an answer Others have explained that this could either be a search… May 12, 2026 at 1:01 am
  • Editorial Team
    Editorial Team added an answer First, you may consider performing your xml mapping within Postgres… May 12, 2026 at 1:01 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
This is what I've got. It works. But, is there a simpler or better
This is what I've got. It works. But, is there a simpler or better

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.