Quick mod_rewrite help on GoDaddy - apache

This htaccess works fine locally, but on GoDaddy the URL isn't caught by the rewrite engine.
RewriteEngine on
RewriteRule ^products/amsoil/(.*)/$ /products.php?amsoil=$1 [L]
RewriteCond %{HTTP_HOST} ^somedomain.com
RewriteRule (.*) http://www.somedomain.com/$1 [R=301,L]
This worked until a few days ago. Basicallywww.somedomain.com/products/amsoil/this-product/ should forward to www.somedomain.com/products.php?amsoil=this-product ....did work, and still works locally however now I just get a 404 error on www.somedomain.com/products/amsoil/this-product/
Any ideas?

I verified that the following script works on our current hosting plans:
RewriteEngine on
rewritecond %{http_host} ^coolexample.com [nc]
rewriterule ^(.*)$ http://www.coolexample.com/$1 [r=301,nc]
There is a possibility that you are on an older version of our hosting plans. If that is the case, you may want to consider upgrading. Check out http://x.co/Zecq for a how-to on upgrading. There is also a link to the 4GH FAQ. Please review that before upgrading to avoid unwanted surprises.

Related

URL not re-writing as expected in apache XAMPP

The requested url is http://localhost/views/items?item=abc I want to rewrite it to http://localhost/views/myfile.php?reqtype=items&item=abc please note that the last keyword of url before query items I want to move to query section as reqtype=items to get this I wrote below code in .htaccess
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^views/(.*)$ views/myfile.php?reqtype=$1&%1 [L,NE]
This code is working well when I tests here verified its output (from this link) by directly pasting in browser as URL worked well. but with xampp (my version is 7.1.28) it is not working. Remember url-rewriting is working for other type of conditions ( means apache configuration is correct and working ) but this particular example is not working, Any solution will be appreciated, Thanks.
Could you please try following, written and tested with shown samples. Please make sure you clear your browser cache before testing your URLs. NOTE that here condition RewriteCond %{ENV:REDIRECT_STATUS} ^$ is very important to stop looping else it will be keep redirecting. I have checked these rules by curl command and they work fine.
RewriteEngine ON
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/views/(items)\?([^\s]*)\s [NC]
RewriteRule ^(.*)$ views/myfile.php?reqtype=%1&%2 [NE,L]

.htaccess RewriteRule don't work

i've been searching on the apache website, stackoverflow's responses, and i couldn't find any answers to me..
All i want is to redirect site.com/stats/ to site.com/pages/stats.php to make the path better and simple. as i said i've been searching it for a whole month, without any answer that could help me... I'm not english so sorry if i made mistakes on this question.
I'm actually on a VPS Debian 7 runing Apache version V2.2.22 (Debian)
My current rules (Maybe wrong ^^) are there :
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.*)$ pages/stats.php <-- not working
RewriteRule ^player/(.*)$ pages/stats_player.p‌​hp?player=$1
I'll really like who will answer this post
FOUND!
i just needed to add these 2 lines :
RewriteRule ^stats/$ pages/stats.php
RewriteRule ^stats$ pages/stats.php
Try this rule
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-]+)$ pages/$1.php
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ pages/stats_player.php?$1=$2 [L]

Apache Rewrite Conditions

I am currently trying to redirect all frontend pages on a Magento install to a specific page, however when I do this, I can no longer gain access to the Magento back office. I have tried the following, but it doesnt appear to work, it still redirects everything.
Any help would be much appreciated.
RewriteCond %{REQUEST_URI} !^/index.php/admin/
RewriteRule ^(.*) new-url [R=301,QSA,L]
Can you try this as your first rule:
RewriteCond %{REQUEST_URI} !/admin/
RewriteRule ^ new-url [R=301,L]
Make sure to test in a new browser.

Using Apache Rewrite to go from HTTP to HTTPS and vice-versa, but I get a 302 response and my app errors out

I really hope someone knows what I'm doing wrong here, cuz I sure don't!
We have a certain page on our site which has account balance information on it, and we want to make it secure with SSL. But we only want this one particular page to be secure. I have the following in the localhost:80 virtualhost, and it works perfect:
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/account\.php(.*) [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,L]
However, as you might guess, we want all other pages to just use HTTP. So I stuck this little snippet into my localhost:443 virtualhost:
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/account\.php(.*) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [QSA,L]
...And that's when the problem happens. I have no problems going back to HTTP, but when I click the link to go to the account page, it changes to HTTPS but I immediately get an error 302 response. I do not get this response when I remove either one of those rewrite rules, it only happens when they are both there.
I have tried replacing [QSA] with [R] and [R=301], to no avail.
(I'm aware that the %{HTTPS} on/off is a bit redundant ;))
So I have two questions:
Is there something I am forgetting or doing wrong that might be causing this?
Is using [QSA] redundant with $1? We use the GET method a lot to specify pages and what not.
We are using PHP 5.2.9 and Apache 2.
Many thanks in advance!!
Brian
Whilst it's on here (and not moved to serverfault).. try
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/account\.php https://%{HTTP_HOST}/account.php [R=301,QSA,L]
HTTP/1.1 302 = Found (and is not an error code), but temporarily at another location.
EDIT
Actually, whilst you are putting the code in separate VirtualHosts, you may as well do
(In :80)
RewriteRule ^/account\.php https://%{HTTP_HOST}/account.php [R=301,QSA,L]
(in :443)
RewriteCond %{REQUEST_URI} !/account\.php$
RewriteRule ^(.*) http://%{HTTP_HOST}$1 [R=301,QSA,L]

.htaccess not working

RewriteEngine on
RewriteCond $1 !^(index\.php|files|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
The website is hosted on the latest version of XAMPP locally. When I load the website with the .htaccess file in place, it won't load at all. I get a server error
What am I doing wrong?
EDIT: Checked log file, here's an error that might help point the issue out. Does this mean that mod_rewrite has not been included?
.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or
defined by a module not included in the server configuration
Change your first line to
RewriteEngine On
Also, replace your RewriteRule with
RewriteRule ^(.*)$ index.php/$1 [L]
If this doesn't help, check your log file. Server errors will normally issue something to the log file.
If that doesn't help, you'd best crank up your RewriteLog and post some of that here.
The first line, as has been pointed out, should be changed :
RewriteEngine On
but you really ought to redirect requests only if they do not already exists (otherwise all your static requests, eg images and css, would go through index.php as well)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Have you made sure to enable mod_rewrite in XAMPP? A quick googling revealed that (at least in older versions of XAMPP), mod_rewrite was not enabled by default. Maybe this is your issue?