Rewrite rules from Apache .htaccess to lighttpd standard - apache

I'm new to lighttpd and I'm having problems with the .htaccess, I know that it's not the same as Apache and you have to do the changes in lighttpd.conf so I'm trying to do my rewrite rules, but they are not working for some reason...
This is my .htaccess file in Apache and I would like if you can convert it for lighttpd so it works on my server, for index.php to open as /index I tried url.rewrite-once = ( "^index$" => "/index.php" ), but it wasn't working so please if you can convert at least the following and if you have time for the other ones convert them as well. By the way, just to let you know, I enabled mod_rewrite from modules.conf so it's possible to use rewrite rules, but as I said I can't convert them right or I don't know what I'm doing wrong ...
ErrorDocument 404 /error.php
RewriteRule ^index$ /index.php [L]
RewriteRule ^view_news/([^/]*)$ /news.php?id=$1 [L]
ErrorDocument 404 /error.php - NOT SOLVED
RewriteCond %{HTTP_HOST} ^your-site\.com$ NOT SOLVED
RewriteRule ^(.*)$ http://www.your-site.com/$1 [R=301,L] - NOT SOLVED
RewriteRule ^index$ /index.php [L] - SOLVED
RewriteRule ^view_news/([^/]*)$ /news.php?id=$1 [L] - SOLVED

Related

Where is my mod rewrite fail?

I have got url
ipaddr/opensys/base/
and some other similar, like
ipaddr/opensys/base/something.php?olol=yep
I want to remove from url "opensys" and display there "center", i want to see this links working:
ipaddr/center/base/
and
ipaddr/center/base/something.php?olol=yep
I did it with symlinks, but it was not good, because system is very difficult and with symlink some plugins not works, I want to do it with .htaccess only, after it all will be ok.
My htaccess is:
but links, which i want to see is not working, why?
RewriteEngine on
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [L]
RedirectMatch 301 ^/opensys/base/(.*)$ /center/base/$1
Redirect works good, but i see 404, rewrite rules is not working. Why?
You also need to handle the /center/base/ now in the .htaccess file as you must be handling opensys earlier. Something like this -
RewriteRule ^/opensys/base/(.*)$ /center/base/$1 [R=301]
RewriteRule ^/center/base/(.*)$ /index.php?args=$1 [QSA,L]
You can use this code in root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} /opensys/(base/\S*)\s [NC]
RewriteRule ^ /center/%1 [R=301,L,NE]
RewriteRule ^center/(base/.*)$ opensys/$1 [L,NC]

.htaccess hide question mark from address

What am I doing wrong?
I have a link :
Link Name
I am need to make an address from:
eshop.mydomain.com/norma/something1/something2/something3/
this adress:
eshop.mydomain.com/norma-something1-something2-something3.html
the only thing I can do is
eshop.mydomain.com/?norma-something1-something2-something3.html
I need to hide the question mark, but I do not have any idea how :(
Here is my .htaccess
#php_value memory_limit 256M
RewriteEngine On
RewriteBase /
RewriteRule /index.php / [R=301]
RewriteRule ^norma/([^/]+)/([^/]+)/([\d\.]+)$ %{DOCUMENT_ROOT}/index.php?$1-$2&-$3.html [L,QSA]
ErrorDocument 404 /doc/e404/
You're adding that question mark in your rewrite rule:
# right here -----------------------------------------------------------v
RewriteRule ^norma/([^/]+)/([^/]+)/([\d\.]+)$ %{DOCUMENT_ROOT}/index.php?$1-$2&-$3.html [L,QSA]
But I suspect it may be a couple of things that's causing this redirect to happen when it really should be a rewrite internally on the server side. Try changing your rules to this:
RewriteEngine On
RewriteBase /
# this L is important ------------v
RewriteRule ^/?index.php / [R=301,L]
RewriteRule ^norma/([^/]+)/([^/]+)/([\d\.]+)$ /index.php?$1-$2&-$3.html [L,QSA]

Apache mod_rewriting not finding any files

OK, so we have a specific set of rewrites that we use on a number of sites due the file structure of our programming. It's never been a problem before until now.
For example, the rewrite:
RewriteRule ^$ Pages/news.php
Instead of directing to http://www.domain.com/wedding-venues-and-caterers-news/Pages/news.php it is redirecting to /path/to/file/public/wedding-venues-and-caterers-news/Pages/news.php and it's 404-ing (/path/to/file being the actual path).
If anyone could shed any light as to why this is happening, or point me in the right direction then I would be eternally grateful.
I am running all of my script and files in a subfolder, there is another .htaccess file in the root folder which I have edited in at the bottom but it doesn't seem to contain anything that could be interfering.
If you require any further information on the server then let me know!
EDIT - Here are all my rewrites as requested.
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^$ Pages/news.php
RewriteRule ^images/([0-9]+)/([0-9]+)/(0|1)/(.*).jpg?$ Classes/Image/timthumb.php?src=http://www.domain.com/wedding-venues-and-caterers-news/images/$4.jpg&h=$1&w=$2&zc=$3
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/([0-9]+)(/)?$ Pages/archives.php?cat_id=$2&page=$3 [NC,L]
RewriteRule ^archives/mon/([0-9]+)/yr/([0-9]+)/([0-9]+)$ Pages/archives.php?mon=$1&yr=$2&page=$3 [NC,L]
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)(/)?$ Pages/archives.php?cat_id=$2 [NC,L]
RewriteRule ^archives/mon/([0-9]+)/yr/([0-9]+)(/)?$ Pages/archives.php?mon=$1&yr=$2 [NC,L]
RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([0-9]+)(/)?$ Pages/article.php?art_id=$3 [NC,L]
RewriteRule ^wedding-venues-catering-rss(/)?$ rss/rss.php [NC,L]
RewriteRule ^Page-Error(/)?$ Pages/errorPage.php [NC,L]
ErrorDocument 404 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 401 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 403 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 404 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 500 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
I also tried to reference the rewrites with absolute URL's, this worked of course, but they were just redirecting instead of rewriting as you might expect.
EDIT - This is the other .htaccess file in the root directory, which is part of their existing site.
#Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
<IfModule mod_rewrite.c>
RewriteEngine on
redirect 301 /Cavendish.htm http://www.domain.com/
redirect 301 /grange.htm http://www.domain.com/
redirect 301 /restaurant/index.html http://www.domain.com/
redirect 301 /news/Save-money-by-booking-wedding-venues-in-Middlesex-at-off-peak-times.asp http://www.domain.com/
redirect 301 /news/default.asp http://www.domain.com/
EDIT - I thought this might be relevant.
The 404 error on the rewrite shows this path -
/l/i/domain.com/public/wedding-venues-and-caterers-news/Pages/news.php
But.. if I edit news.php and request SCRIPT_FILENAME it gives me the path..
/services/webpages/l/i/domain.com/public/wedding-venues-and-caterers-news/Pages/news.php
My guess is that something is affecting the default path.
Furthermore I have tried basic rewrites at root level, but these also 404.
Finally the issue has been solved.
As the server is hosted with BT Business I decided to email them to see if they could help.
A guy replied saying he had logged in to the server and modified the .htaccess and it now works fine.
He simply added the subfolder in front of the rewritten URL's.
IE:-
RewriteRule ^$ Pages/news.php
Became: -
RewriteRule ^$ wedding-venues-and-caterers-news/Pages/news.php
I am still unsure why the subdirectory is needed when the .htaccess file is inside that directory, my guess is it is something to do with their server settings.

htaccess to remove the GET params, but still pass the value

I currently have it set to redirect www.foo.***/2 to www.foo.***/index.php?id=2, but i am trying to get it to redirect without displaying the URL.
I want the URL to stay as www.foo.***/2 but atually deliver www.foo.***/index.php?id=2
my htaccess file:
Options +FollowSymlinks
RewriteEngine ON
RewriteRule ^$ h**p://server/~user/folder/sub/index.php [L]
ErrorDocument 404 h**p://server/~user/folder/sub/ERROR/
ErrorDocument 500 h**p://server/~user/folder/sub/SERVER/
RewriteRule ^(error)/([0-9A-Za-z+]+)?$ h**p://server/~user/folder/sub/index.php?action=ERROR [L,NC]
RewriteRule ^(server)/([0-9A-Za-z+]+)?$ h**p://server/~user/folder/sub/index.php?action=SERVER [L,NC]
RewriteRule ^([0-9A-Za-z+]+)?$ h**p://server/~user/folder/sub/index.php?id=$1 [L,NC]
any help would be great thanks!
bo huttinger
thanks to awesome spamz protectionz, I subsituted stars for letters in the post
It was a 'same domain' issue. If you call a location on the same server, it doesn't rewrite the URL in the bar
solution: instead of using:
h**p://server/~user/folder/sub/index.php?id=$1 [L,NC]
use this:
/home/~user/folder/sub/index.php?id=$1 [L,NC]
hope this helps!

htaccess redirect problem

I'm trying to get my .htaccess to redirect all requests to the /blogs directory, except for requests that start with /staff. This is what I have so far:
RewriteEngine On
RewriteRule ^staff(.*)$ staff/$1 [L]
RewriteRule ^(.*)$ blogs/$1 [L]
It works fine for every case, except when I do http://mydomain.com/staff or http://mydomain.com/staff/alice in which case I get a 500 Internal Error.
What am I doing wrong?
Try this:
RewriteRule ^staff/ - [L]
RewriteRule !^blogs/ blogs%{REQUEST_URI} [L]
What is logged to error.log? The error may be coming from either mod_rewrite or from your application itself.