# .htaccess rewrite

**URL:** <https://www.ruby-forum.com/t/htaccess-rewrite/150297>\
**Category:** Rails\
**Created:** [October 7, 2008, 1:29am UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297 "2008-10-07T01:29:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 1:29am UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/1 "2008-10-07T01:29:15Z")

</div>

can someone help me with an .htaccess rewrite?

i’m trying to convert all requests to “/?spot=8888” to be “/locations/  
888”.

thanks.

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 3:01am UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/2 "2008-10-07T03:01:08Z")

</div>

Hi,

Try this .htaccess file:

RewriteEngine On  
RewriteCond %{SCRIPT\_FILENAME} !-f  
RewriteCond %{SCRIPT\_FILENAME} !-d  
RewriteRule ^/locations/(.\*)$ /?spot=$1

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 4:39am UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/3 "2008-10-07T04:39:29Z")

</div>

That didn’t work (and appears to be backwards). I tried the following  
w/ no luck…

RewriteRule ^/?spot=(._)$ /locations/$1  
RewriteRule ^/?spot=(._)$ /locations/$1 [R=301,L]  
RewriteRule /?spot=(.\*)$ /locations/$1 [R=301,L]

This is also for a subdomain under Rails…

[http://m.domain.com/?spot=8888](http://m.domain.com/?spot=8888)  
to  
[http://m.domain.com/locations/8888](http://m.domain.com/locations/8888)

On Oct 6, 5:34 pm, Gerson M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 5:08pm UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/4 "2008-10-07T17:08:50Z")

</div>

@abhishek - you can catch all traffic on a port and redirect like this  
(but beware of an infinite loop)…

RewriteCond '%{SERVER\_PORT}" “^12004$”  
RewriteRule “^(.\*)$” “http://%{SERVER\_NAME}$1” [R=301,L]

Anyone able to help me with a redirect from “/?spot=8888” to “/  
locations/8888”? Simple yet elusive ☹

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 9:43am UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/5 "2008-10-07T09:43:36Z")

</div>

guys even my problem is somewhat related to the same as currently hosted  
my  
application on bluehost which is running on port 12004. so when every i  
try  
to access my site “http:///www.mydomain.com” its redirect me to "  
[http://mydomain.com:12004](http://mydomain.com:12004)" so if some one guide me that will be very  
helpful  
thanks…

regards  
abhishek

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 5:34pm UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/6 "2008-10-07T17:34:51Z")

</div>

Hey thanks sav but still no success…  
RewriteRule ^$ index.html [QSA]  
RewriteRule ^([^.]+)$ $1.html [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(._)$ dispatch.cgi [QSA,L]  
RewriteCond '%{SERVER\_PORT}" “^12004$”  
RewriteRule "^(._)$" “http://%{SERVER\_NAME}$1” [R=301,L]

This is my .htaccess setting and seriously no idea… wat to do… new  
in  
deployment.  
Note i don’t have an root access… the only file which i can editi s  
.htaccess and other files from public folder…

Thanks sav if you can help me

regards  
Abhishek S.

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/7 "2008-10-07T20:40:42Z")

</div>

Hey Hassan,  
Thanks for reply the main issue is that i don’t have an access to apache  
folder currently my application running on Bluehost with a dedicated IP  
address. And even i am not able to access rewrite.log file as well ☹ so  
that is why my is screwed up… So please guys help me…

Regards  
Abhishek shukla

On Tue, Oct 7, 2008 at 11:04 PM, Hassan S. \<

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/8 "2008-10-07T22:07:07Z")

</div>

On Tue, Oct 7, 2008 at 11:39 AM, Abhishek shukla [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thanks for reply the main issue is that i don’t have an access to apache  
> folder currently my application running on Bluehost with a dedicated IP  
> address. And even i am not able to access rewrite.log file as well

You should be able to set this up through .htaccess with logging  
set to go to a directory you have write permissions to.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Sav](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Sav](https://www.ruby-forum.com/u/Sav)\
**Post date:** [October 7, 2008, 7:35pm UTC](https://www.ruby-forum.com/t/htaccess-rewrite/150297/9 "2008-10-07T19:35:24Z")

</div>

On Mon, Oct 6, 2008 at 7:30 PM, Sav [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> That didn’t work (and appears to be backwards). I tried the following  
> w/ no luck…

You probably want to turn on/up rewrite logging for more information  
on /why/ you’re having “no luck”, instead of guessing 🙂

Something like:

RewriteLog “/usr/local/apache-httpd-2.2.9/logs/rewrite.log”  
RewriteLogLevel 3

See the httpd docs for more info.

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid
