1

I have a website that I'm trying to change the URLs on. All of the URLs start with http://domain.com/?

For example, http://domain.com/?index

I just want to remove the question mark. I don't care if it appears in the address bar, I just want my users to be able to access the pages on the site without having to type the question marks.

So, if a user wants to access http://domain.com/?index, I want them to be able to access it by typing http://domain.com/index.

Is this possible using .htaccess?

I've searched around and tried a few different things for a few days now and still can't figure out a way to accomplish what I'm trying to do.

Any help is appreciated.

Thanks.

Thomas Spade
  • 724
  • 6
  • 11
  • 25

2 Answers2

0

Try:

RewriteEngine On

# Match against the request instead of the URI
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?([^&\ ]+)&?([^\ ]*)
RewriteRule ^$ /%1?%2 [L,R=301]

This takes URI's like http://example.com/?path/to/file.txt and redirects the browser to http://example.com/path/to/file.txt. The browser will display that URL in the location bar instead. This is, of course, assuming that if someone actually goes to that URL, that there is something there to be served other than a 404.


EDIT

To internally map none-query string URLs to the one with a query string:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?$1 [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • This does successfully redirect the pages, but it gives me a 404 error because there isn't anything there to be served. I think this is just backwards. Instead of having http://example.com/?path/to/file.txt redirect to http://example.com/path/to/file.txt, I'm looking to have http://example.com/path/to/file.txt redirect to http://example.com/?path/to/file.txt. Is this possible? Thanks for your help – Thomas Spade Sep 03 '13 at 19:56
  • @ThomasSpade But you want the browser to *not* see the `?` (query string), right? Redirecting **to** the URL with the query string defeats that purpose. – Jon Lin Sep 03 '13 at 20:10
  • Well I don't really care what the browser sees. It's not really about having clean URLs or SEO. All of my users get a URL that they will need to send to people and advertise with and they don't like the question mark in the URL. They just want to be able to access the page without having to type the question mark. – Thomas Spade Sep 03 '13 at 20:13
  • Doesn't seem to be working. No matter what I type in the address bar or what links I click on, every link just takes me to the homepage of the website. – Thomas Spade Sep 03 '13 at 20:23
-1

Try using :

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ /?$1 [NC]

in your .htaccess file ,

let me know if it works.

Hossam
  • 1,126
  • 8
  • 19